Method of initializing memory in C language

I don't know if you have tried to use "hot and hot ..." when using vs. The main reason for this is that the software defaults to filling all uninitialized stack memory with 0xcc when initializing memory, corresponding to The Chinese character string is hot and scalding ..., the uninitialized heap (new) memory is filled with 0xcd, which corresponds to the Chinese character string is Tuntuntun ...... And generally use the memory to reset the content in the memory, generally we use the memset function




char buf [ 1024 ];
 // When using this address, we need to clear the memory information. There are generally two ways, one is to complete during the run, and the other is to complete during the compilation: 

// 
memset (buf, 0 during the run , sizeof (buf)); // char buf [ 1024 ] = { 0 } during compilation


 

Recommended use = {0} This form is more efficient.
When I first learned the data structure and algorithm, because the C language foundation was not good, and there was no review, I often encountered the situation that the array was not empty when writing the data structure, and later re-added this part of the content, only to find out that this is the case. Low-level errors.


 
 

Original: https://www.jianshu.com/p/7b184fcd880b

Guess you like

Origin www.cnblogs.com/code1992/p/12746410.html