write a program using scope resolution operator

The scope resolution operator (::) is used to bind a particular namespace to an identifier. It is mainly used to access the global variables and functions outside a class or a function. To write a program using scope resolution operator, you can use the following code: 

#include <iostream.h>

#include<conio.h>

int globalVar = 10; // global variable

 int main()

{

 int localVar = 20; // local variable

 clrcsr();

 // Accessing global variable using scope resolution operator

 cout << "Global Variable: " << ::globalVar << endl;

 // Accessing local variable directly

 cout << "Local Variable: " << localVar << endl;

getch();

return 0;

}

Md Ashraf

'KNOWLEDGE WITH ASHRAF' is the platform where you find all the type of knowledge especially on programming based. Our goal is to give you a deeper grasp of technology in specifics that will help you increase your knowledge.

Previous Post Next Post

Contact Form