Unary Operator in C++
  • Share this blog:

‘::’ Unary operator

The scope operator is used to refer to member of global namespace between the global name space does have the name, the rotation ::

  • Member name refers to a member of the global namespace.
  • This can be useful for referring to members of global namespace whose names have been hidden by names declared in nested local scope. Unless we specify to the compiler in which namespace to search for a declaration, the compiler simple searches the current scope and any scopes in which the current scope is nested, to find the declaration for the name

  Namespace is a collection of

  • variables
  • Functions
  • Classes

  namespace N { Classes }   int x;  global variable   void main ();                                    global name space {                                                        int x=10; int y =20;                                       void main() cout <<y;   - > 20                            { cout<<x; - > 20                                  int x=20; }                                                        cout<<x; -> 20 cout<< :: x; cout<<N :: x;    

  • global name space - > unnamed

Unary operator in C++ with Example

# include <iostream.h> int x=10; void main() { int y=20; cout<< “\n local variable y=” <<y; 20 cout<<”\n global variable u=”<<x;10 cout<<”\n global variable x=”<<  :: x; }


# include <iostream.h> { int x=10; int y=10; void main() { int z=30; int x=40; { cout<< end l<< x;               // 50 cout<< end l << :: x; //10 cout<<end l << z;       //30 cout<< end l<<y;        // 20 cout<< end l<<::y; } cout << endl<<x;   // 40 cout << endl << Z; //30 cout << endl<<:: x; //20 coout<<endl<<::y;  //20 }

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses


About Author
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.

Stay Updated

Get stories of change makers and innovators from the startup ecosystem in your inbox