Simple Scope Resolution Operator Example Program In C++

Read About C++ Operators

Definition

The scope resolution operator is used for the Unary scope operator if a namespace scope  (or) Global Scope

Scope Resolution Operator Syntax

:: identifier   // for Global Scope
class-name :: identifier  // for Class Scope
namespace :: identifier   // for Namespace Scope

//simple syntax
:: global variable name

For more information on Scope Resolution Operator, check this link

http://www.cpp.thiyagaraaj.com/home/blog-1/scoperesolutionoperatorinc

Scope Resolution Operator Example Program

// Header Files
#include<iostream>
#include<conio.h>
#include<stdio.h>

//Main Function

using namespace std;

int a = 100; //Global variable

int main ()
{
	// Local Variable Declaration
    int a = 200;
    
    cout << "Simple Scope Resolution Example Program In C++\n";
    
    // Print Global Varibale
    cout << ::a<< endl; 
    
    // Print Local Varibale
    cout << a << endl;

	//Main Function return Statement
	return 0;
}

Sample Output

Simple Scope Resolution Example Program In C++
100
200