Predict the output : Global Variable


#include
#include
#include
 
using namespace std;
int gVar = 20;

int main()
{
    int gVar = gVar;
    cout << gVar;

    _getch();
    return 0;
}
 
 
Answer: Garbage Value.
First var is declared, then value is assigned to it. As soon as var is declared as a local variable, it hides the global variable var.

Comments