Cpp code to access same name of variable from global and also from local?

All QuestionsCategory: Cpp LanguageCpp code to access same name of variable from global and also from local?
Chetan Shidling Staff asked 5 years ago

info

1 Answers
Chetan Shidling Staff answered 5 years ago

Code

#include <iostream>
using namespace std;
int a=5;//global variable
int main()
{
int a=3;//local variable
cout<<“value of a:”<<a;
cout<<“\nGlobal value of a:”<<::a;
return 0;
}

By using scope resolution we can access the global variables.