Scope resolution operator or Scope access operator (::)

C++ language programs are defined in block structure.With the help of blocks we can show different parts (scopes) of a program. If the global variable and local variable of program has same name then the scope resolution operator(::) is used to access the global variable.
C++ लैंग्वेज प्रोग्राम्स को ब्लॉक स्ट्रक्चर में परिभाषित किया जाता है। ब्लॉक की सहायता से हम एक प्रोग्राम के विभिन्न भागों (स्कोप) को प्रदर्शित कर सकते है। यदि किसी प्रोग्राम में ग्लोबल एवं लोकल वेरिएबल का नाम एक समान हो तब स्कोप रेसोल्यूशन ऑपरेटर(::) का प्रयोग कर ग्लोबल वेरिएबल को एक्सेस किया जा सकता है।      

Syntax:- ::variable_name;
Example:- ::x;

In below code, x is define in both outer block and inner block.Now, To access outer block variable x , scope resolution operator (::) will be used.
निम्न कोड में x वेरिएबल को आउटर एवं इनर ब्लॉक में दर्शाया गया है। अब आउटर ब्लॉक के x वेरिएबल को एक्सेस करने के लिए स्कोप रेसोल्यूशन ऑपरेटर(::) का प्रयोग किया जायेगा। 
{
int x=10;
{
int x= 20;
cout<<"Inner x= "<< x<<endl;
::x=::x+50;
cout<<"Outer x ="<< :: x<<endl;
}
cout<<"Outer x= "<< x<<endl;
}

In addition, scope resolution operator(::) is also used to relate a class and its outside member functions.
साथ ही, स्कोप रेसोल्यूशन ऑपरेटर(::) का प्रयोग एक क्लास एवं उसके आउटसाइड मेम्बर फंक्शन में सम्बन्ध स्थापित करने के लिए भी किया जाता है।  
Syntax:- 
return_type class_name :: member_function_ name(){
------------------
------------------
}

Example:-
void student::getstudent(){
statements;
.................
.................
}

Note:- scope resolution operator(::) is also used to access the static variables of class.
स्कोप रेसोल्यूशन ऑपरेटर(::) का प्रयोग क्लास के स्टेटिक वेरिएबल को एक्सेस करने में भी किया जाता है। 
Syntax:-
class_name::static variable_name;
Example:-
student::count;

No comments:

Post a Comment