Like the title says. I was under the impression that a char is the same as a short short unsigned int
would be, allowing any value from 0 to 255. According to the debugger on Visual Studio, whenever I declare a char
, it starts at -52 'Í'
. Why is this the case, and how is this possible?

- 189
- 10
-
`char` can be signed or unsigned at the implementation's discretion, as long as a `signed char` can contain the basic execution character set. There's no such thing as a `short short unsigned int`. You cannot rely on the uninitialized value being `-52`. – Crowman Oct 09 '14 at 02:40
-
3It starts at a garbage value because you have not initialized it. – Sergey Kalinichenko Oct 09 '14 at 02:41
-
1I realize that there is no such thing as a short short unsigned int; that's why I said "would be". – Smurfton Oct 09 '14 at 03:14
-
1Why is this rated down? I don't understand how this question is valueless, or a bad question. – Smurfton Oct 09 '14 at 03:18
-
@dasblinkenlight in MSVC debug mode it will initialized variables with various patterns for easier debugging http://stackoverflow.com/questions/370195/when-and-why-will-an-os-initialise-memory-to-0xcd-0xdd-etc-on-malloc-free-new – phuclv Oct 09 '14 at 03:59
-
@Smurfton the value depends on which type you're using (char, short, int...) but the pattern will be 0xCC – phuclv Oct 09 '14 at 04:00
2 Answers
It is unspecified whether char is signed or unsigned in your case it is signed, this is covered in the draft C99 standard section 6.2.5
Types which says:
The three types char, signed char, and unsigned char are collectively called the character types. The implementation shall define char to have the same range, representation, and behavior as either signed char or unsigned char.35)
unintialized automatic variables have indeterminate values and so their initial value is unpredictable.
Since we are talking about Visual Studio, it would appear according to the Wikipedia article Magic number (programming) it uses CC
to mark unitialized stack memory:
Used by Microsoft's C++ debugging runtime library and many DOS environments to mark uninitialized stack memory. CC resembles the opcode of the INT 3 debug breakpoint interrupt on x86 processors.
which would explain the -52
you are seeing but this should not be considered reliable and is not portable. Should be noted that using indeterminate value invokes undefined behavior.

- 154,301
- 39
- 440
- 740
Because Visual Studio will initialize the stack memory to 0xCC in debug mode, 0xCC is the machine code of int 3 (interrupt directive), and 0xCC is -52 in decimal.
-
more on this http://stackoverflow.com/questions/370195/when-and-why-will-an-os-initialise-memory-to-0xcd-0xdd-etc-on-malloc-free-new – phuclv Oct 09 '14 at 03:57