Simple Scope Resolution Operator Example Program In C++
On this page (7sections)
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.
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
Related Pages
Learn the concept first, then study the code:
- C++ Programs — Browse all C++ Programs.
- Arithmetic Operators Example in C++ — Tutorial — arithmetic, relational and logical operators.
- Simple Relational Operator Example Program In C++ — More in c operator example programs.
- Simple Logical Operators Example Program In C++ — More in c operator example programs.
Frequently Asked Questions
What does this C++ program do?
It is a C++ example program that demonstrates Simple Scope Resolution Operator, including the complete source code and the expected sample output.
How do I compile and run this C++ program?
Save the code in a `.cpp` file, compile it with `g++ filename.cpp -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses core C++ syntax, illustrating a common pattern in C++ programming.