What will be the output of the following C++ code? using namespace std; int x…
2025
What will be the output of the following C++ code?
using namespace std;
int x = 1;
int main()
{
int x = 2;
{
int x = 3;
cout << ::x << endl;
}
return 0;
}
Answer: A. 1 — Answer: a Explanation: While printing x we are using :: operator hence the refernce is given to global variable hence the global variable x = 1 is printed.
- A.
1
- B.
2
- C.
3
- D.
123
Attempted by 110 students.
Show answer & explanation
Correct answer: A
Answer: a
Explanation: While printing x we are using :: operator hence the refernce is given to global variable hence the global variable x = 1 is printed.
Loading lesson…