Copyright © Programs ++
Design by Dzignine
Tuesday 24 January 2012

Using scope resolution operator

The scope resolution operator ( :: ) is used when we have to direct the compiler to use a variable with a particular scope. It comes handy when we have a global and a local variable of the same name as shown in the following example : 

// Program to show the use of scope resolution operator
#include <iostream>
using namespace std;
int x = 25; // global variable

int main()
{
    int x; // local variable
    cout<<" Entre the value of x : ";
    cin>>x;
    cout<<" \n Value of x stored as variable with LOCAl scope : "<<x;
    cout<<" \n Value of x stored as variable wih GLOBAL scope : "<<::x; // scope resolution operator
    cin.get(); // to show the output
    return 0;
} // end of main
 




























































Scope resolution operator demo program 













0 comments:

Post a Comment

Comment Here....