Open In App

C++ | Misc C++ | Question 2




#include<iostream>
using namespace std;
int x = 1;
void fun()
{
    int x = 2;
    {
        int x = 3;
        cout << ::x << endl;
    }
}
int main()
{
    fun();
    return 0;
}

(A) 1
(B) 2
(C) 3
(D) 0

Answer: (A)
Explanation: The value of ::x is 1.

The scope resolution operator when used with a variable name, always refers to global variable.
Quiz of this Question

Article Tags :