http://blog.csdn.net/songuooo/article/details/7819790
1. Required Header Files
C for <memory.h> or <string.h>
<cstring> in C + +
2. Function prototypes
void * memset ( void * ptr, int value, size_t num);
Assign value to num bytes starting with the address PTR, note that each byte in the NUM byte that starts with PTR is assigned value as value.
(1) If PTR points to a char address, value can be any of the character values;
(2) If PTR points to a non-char type, such as an int address, to assign the correct value, value can only be 1 or 0, because 1 and 0 are converted to binary after each bit is the same, set int is 4 bytes, then -1=0xffffffff, 0=0x00000000.
example, assign the correct value correctly:
[CPP]
int a[2];
Memset (A,-1, sizeof a);
The assignment process is as follows:
Because the int is four bytes, the memset is assigned by byte-by-bit, so a[0] or a[1] is actually a four-byte value, which is 0xffffffff=-1.
Example, Error assignment:
[CPP]
int a[2];
Memset (A, 1, sizeof a);
The assignment process is as follows:
The value of a[0] is actually 0x01010101=16843009, so it's not what we expected.
Go Memset-C + + in