I have encountered the following code:
#include
using namespace std;
int i = 1;
int main(int argc,char ** argv)
{
int i = i;
cout&l
The int i = i;
statement in main()
declares a local variable that hides the global variable.
It initializes itself with itself (which has an indeterminate value). So the global i
simply isn't used.
In C++, it is possible to access the global variable if you have a local variable with the same name but you have to use the scope resolution operator ::
change the line:
int i = i;
to
int i = ::i;
and the program will compile and work