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


Warning: Trying to access array offset on false in /home3/indiakep/public_html/wp-content/plugins/dw-question-answer/inc/Template.php on line 8
All QuestionsCategory: Cpp LanguageHow to access global and local of same variables and display both, write a Cpp code?
Chetan Shidling Staff asked 6 years ago

info

1 Answers
Chetan Shidling Staff answered 6 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