Is this local variable shading / hiding another normal or error in Visual Studio?

I greatly simplified this question since the same problem arises in a simpler case:

#include <iostream>

int height;    
int main()
{
    std::cout << height; // Visual Studio debugger shows this value as -858993460    
    int height;
}

enter image description here

The problem seems to be that the debugger is displaying the wrong value for the variable. The value of the variable is correct, since printing the variable shows the correct global height value, 0.

+6
source share
1 answer

You are right, the global variable is heightnot obscured until the automatic variable is declared heightin the final statement main().

std::cout << height;will use a global variable height.

, . height, 0xCCCCCCCC, -858993460 .

height , , .

+8

All Articles