Write a program to demonstrate scope resolution operator in c++

//this is a program to demonstrate scope resolution operator in c++
#include<iostream>
#include<conio.h>
int x=10;
using namespace std;
int main()
{
int x=20;//local to main()

//accessing local varianle
cout<<"\nMain: x = "<<x;

//accessing global variable
cout<<"\nGlobal: x = "<<::x;

//block body
{
int x=30;

//accesing local variable
cout<<"\nBlock: x = "<<x;

//accessing global variable
cout<<"\nGlobal: x = "<<::x;

}
getch();
return 0;

}

Previous
Next Post »