CS Electrical And Electronics
@cselectricalandelectronics

How to access global and local of same variables and display both, write a Cpp code?

All QuestionsCategory: Cpp LanguageHow to access global and local of same variables and display both, write a Cpp code?
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 b=3;//local variable
cout<<“value of b:”<<b;
cout<<“\nGlobal value of a:”<<a;
{
int a = 8;
cout<<“\nvalue of a:”<<a;
}
cout<<“\nvalue of a is:”<<a;
return 0;
}

Output:

value of b:3
Global value of a:5
value of a:8
value of a is:5