Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

C++ | Misc C++ | Question 2

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article




#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

My Personal Notes arrow_drop_up
Last Updated : 29 Oct, 2018
Like Article
Save Article
Similar Reads