0

What is the output of the following C++ program?

[gamipress_button type=”submit”  label=”Run Code Online” onclick=”window.open(‘https://coderseditor.com’,’_blank’)”]


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

Output:
10

The global variable is referred to if the Scope Resolution Operator is put in front of a variable name. Therefore, the programme above will not compile if the following line is removed.

Studently Changed status to publish October 11, 2022