Scope resolution operator in C++

:: is called scope resolution operator, it is used to access global version of a variable.
 
#include<iostream>
#include<conio.h>
using namespace std;
// here x is global variable
int x=100; 

int main(){
// here x is local variable for main function
int x=10;

// accessing local variable
cout<<x<<endl;

// accessing global version of x variable using scope resolution operator
cout<<::x<<endl;


getch();
return 0;
}
© 2016 - 2022, All Rights are Reserved.