Scope Resolution Operator in CPP

Scope resolution operator is used to specify the scope of a member function. It is used to access a global variable.

#include<iostream.h>
#include<conio.h>
#include<string.h>

class A			
{		
int rno;	
char name[10];			
public:
void get()
{			 
cout <<"enter your name" << endl;			 
cin >>name;			 
cout <<"enter your rollno"<< endl;
cin >>rno;			 
}
void show();			
};			
void A ::show()			
{			 
cout << name << "\t" << rno;
}
void main()
{
A a1;
clrscr();
a1.get();
a1.show();
getch();
}

Output:

enter your name
tanmay
enter your rollno
100
tanmay 100

 

Leave a Reply