H
H
h45h472021-11-23 11:40:38
C++ / C#
h45h47, 2021-11-23 11:40:38

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.

spoiler
619ca8af9f7a6693991319.png

But why exactly "M", does this have some kind of sacred meaning? Or is it a reference to an ancient meme?
spoiler
619ca8e456368682024840.jpeg


Tested on more than one computer and not only by me, so this is not an accident.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Korotenko, 2021-11-23
@h45h47

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.

R
res2001, 2021-11-23
@res2001

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 question

Ask a Question

731 491 924 answers to any question