1. The FIRST example to show what the global variable is:
#include <iostream>
int a{2};
int main()
{
std::cout << "a = " << a << std::endl;
a = 4;
std::cout << "a = " << a << std::endl;
a = 10;
std::cout << "a = " << ::a << std::endl;
return 0;
}
2. The global vaiable and local variable could have same name:
The results:
a = 2
a = 4
a = 2
The corresponding codes:
#include <iostream>
int a{2};
int main()
{
std::cout << "a = " << a << std::endl;
int a = 4;
std::cout << "a = " << a << std::endl;
std::cout << "a = " << ::a << std::endl;
return 0;
}
The reason behind :: is the gloabl has no name for its functional area.