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. 1Answer: 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.

  1. A.

    1

  2. B.

    2

  3. C.

    3

  4. 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.

Explore the full course: Nta Ugc Net Paper 2

Loading lesson…