Given the following program: #include<iostream> using namespace std; int x = 100
ID: 3733486 • Letter: G
Question
Given the following program:
#include<iostream>
using namespace std;
int x = 100;
int main() {
int x = 220;
cout << "1st output statement: x = " << x << endl;
cout << "2nd output statement: x = " << ::x << endl;
{
int x = 300;
cout << "3rd 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 = 220 // local variable value
2nd output statement: x = 100 //global variable value
3rd output statement: x = 300 inside block local variable value.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.