我们经常将memset用在初始化中,其实还可以这样方便的使用它;
给数组中的一部分初始化;
看例子:
1
2
3
4
5
6
7
8
9
10
11 |
#include<iostream> #include<string.h> using
namespace std ; int main() { int
a[21] = {0} ; memset (a+4,-1,5* sizeof (a[0])) ; for ( int
i = 0 ; i < 20 ; i++) cout << a[i] << ‘ ‘
; cout << endl ; return
0 ; } |
输出结果为;
0 0 0 0 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0
原文:http://www.cnblogs.com/scottding/p/3729471.html