Given the following program: #include<iostream> using namespace std; int x = 10;
ID: 3733487 • Letter: G
Question
Given the following program:
#include<iostream>
using namespace std;
int x = 10;
int main() {
int x = 20;
{
int x = 30;
cout << "1st output statement: x = " << x << endl;
}
cout << "2nd output statement: x = " << x << endl; // use scope resolution operator ( :: ) to access global x
cout << "3nd output statement: x = " << ::x << endl;
return 0;
}
What are the values of x in the following output statements?
1st output statement: x = ?
2nd output statement: x = ?
3rd output statement: x = ?
Explanation / Answer
Answer:
1st output statement: x = 30 //Inside block local variable value
2nd output statement: x = 20 //main function local variale value
3rd output statement: x = 10//global variable value.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.