You could always just use better variable naming conventions. Using "x" for the name of every variable doesn't help you, and it doesn't help anybody looking at your code.
I guess u didn't understood what i was asking.....i am not talking about the global variable ....iam talking about the local variable inside the main....but thanx anyways i was able to solve this problem
int x=0; // global x
int main()
{
int x=1; // main x
{
int x=2; // block x
cout<< x<<endl; // prints block x
cout<< ::x <<endl; // prints global x accessed with :: scope resolution operator
// there is no way to access main x from here
} // block x dies here
cout<< x; // prints main x
cout <<::x; // prints global x
return 0;
}
The basic rule is a name in an inner scope hides the name in all outer scopes unless the scope resolution operator can be used to access it which is not possible with function scope local variables.
#include<iostream.h>
int x=0;
int main()
{
int x=1;
{
cout<<x;//access it before declaring variable in this local scope
int x=2;
cout<<::x;
cout<<x
}
return 0;
}