Are garbage values in newly declared variables random?

Antoneo

Diamond Member
May 25, 2001
3,911
0
0
I'm guessing that it is not since the value in my locals/watch window doesn't change. Correct?
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
IIRC it depends on the compiler and options used. But I think it's safe to assume that you can't assume anything about the initial values.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Depends. In VC6++ the memory is usually initialized differently depending on if it's
- a debug build
- a release build
- you're using a tool like BoundsChecker

But in VC6 debug build at least some memory is always set to 0 or cdcdcdcd or other fixed values. This is one of the caused of "works in debug, fails in release."

Also, regardless of the initial values, some stack corruption bugs like setting x[5] = 20 when you've only allocated 5 elements ( int x[5] ) will keep corrupting the stack the same way every time.