Open In App

C++ | Misc C++ | Question 2

Like Article
Like
Save Article
Save
Share
Report issue
Report




#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


Last Updated : 29 Oct, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads