CS Electrical And Electronics
@cselectricalandelectronics

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?
CS Electrical And Electronics Staff asked 4 years ago

info

1 Answers
CS Electrical And Electronics Staff answered 4 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.