Answer to Question #242121 in C++ for William

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.


1
Expert's answer
2021-09-25T05:20:46-0400
#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!

Comments

William
06.10.21, 11:25

Thanks a ton AssignmentExpert

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS