Question #242121

Write a program in which there is a global variable, a local variable for main function and a variable in a nested scope inside main, with the same name. Print all the three variables.


Expert's answer

#include<iostream>
using namespace std;
int x =5//Global variable
int main(){
	cout<<"The variable value is : "<<x<<endl;
	int n=4;
	if(n==4){
		x = 10;
			cout<<"The variable value is : "<<x<<endl;
	}
	x=40;
		cout<<"The variable value is : "<<x<<endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS