Skip to main content

Simple Scope Resolution Operator Example Program In C++

1 min read
Share:
On this page (6sections)

About this program

This is an example program in c operator example programs. Read the concept first: Arithmetic Operators Example in C++, then study the code and output below.

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

Learn the concept first, then study the code:

Related Tutorials

Search tutorials