C++ | Misc C++ | Question 2

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


(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

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

My Personal Notes arrow_drop_up
Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.