C plus plus programming
June 3, 2026 1 min read

Scope Resolution Operator in C++: Accessing Local and Global Variables

HS
HEMANT SINGH
Technical Writer & Educator

:: 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;
}

In this category