Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to implement memset in c++? Why is it ok to initialize an integer array to 0, and initializing 1 will produce a seemingly random value?
How to implement memset in c++? Why is it ok to initialize an integer array to 0, and initializing 1 will produce a seemingly random value?
The memory size occupied by characters is 1 byte, and the memset function is also assigned by byte, so there is no problem with your output.

The second initialization variable is an integer. Do you use memset or byte assignment? For example, after the assignment of memset(a, 1, sizeof(int)) is completed, the value of a is actually 0x00101,which is 65438 in decimal.

Secondly, 0 means that all bytes are 0, so you can also initialize int by byte.