• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Unary Operator in C++

‘::’ 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





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


Review Date
Reviewed Item
Unary Operator in C++
Author Rating

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Unary Operator in C++"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Site Disclaimer, Copyright © 2016 - All Rights Reserved.


    Please leave a message and we'll get back to you soon.

    I agree to be contacted via e-mail.