Answer the question
In order to leave comments, you need to log in
Why are arrays in C filled with "M"?
In C, arrays that are not filled when they are declared are automatically filled with the "M" symbol.
Answer the question
In order to leave comments, you need to log in
uninitialized variables are not set to zero; they are initialized to special fill patterns, 0xcc and 0xcd (depending on whether the memory was allocated on the stack or the debug heap).
The debugger can also be configured to break when uninitialized memory is read (
though there are probably some restrictions on when this feature can be used) So it's funny. It works in debug, but not in release.
They are not filled with M.
If an automatic array is declared on the stack without an initializer, then memory on the stack is simply allocated (decrement / increase of the stack counter register), no "shadow" assignments to the elements occur, the array elements take on the values that were in these memory cells previously.
It's the same with a dynamic array, only the memory allocation mechanisms are different.
At any address in memory, there is always some value, even if this memory has not yet been allocated, simply because the memory chip has already been inserted into the motherboard and power has been applied to it.
Perhaps in your case this is not an accident - you do not give the code by which you allocate memory.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question