-
Notifications
You must be signed in to change notification settings - Fork 0
用法注意
int array[5] = {1,4,3,5,2};
memset(array,1,5*sizeof(int)); // 注意
for(int k = 0; k < 5; k++)
cout<<array[k]<<' ';
输出的结果就是:
16843009 16843009 16843009 16843009 16843009
因为memset是以字节为单位就是对array指向的内存的5个字节进行赋值,每个都用ASCII为1的字符去填充,转为二进制后,1就是00000001,占一个字节。一个INT元素是4字节,合一起就是00000001000000010000000100000001,就等于16843009,就完成了对一个INT元素的赋值了。
所以用memset对非字符型数组赋初值是不可取的。
例如:有一个结构体Some x,可以这样清零:
memset( &x, 0, sizeof(Some) );
如果是一个结构体的数组Some x[10],可以这样:
memset( x, 0, sizeof(Some)*10 );
STL
标准STL序列容器
* vector
* string
* deque
* list
标准STL Associative Container
* set
* multiset
* map
* multimap
非标准关联容器
* hash_set
* hash_multiset
* hash_map
* hash_multimap
* unordered_set
* unordered_multiset
* unordered_map
标准非STL容器
* array
* stack
* queue
* hash_multimap
数据结构的对比
常见面试题
面试题词汇
TopK
5亿个int找中位数
多线程-生产者消费者模式
Suggestion
* Suggestion for job