C++ Operators

All C-Language operators can be used in C++. In addition C++ has some more operators like:

<< Insertion Operator - use for displaying the output.
>> Extraction Operator - use for input.
:: Scope resolution operator - use to access global variable.
endl Line feed operator - use to transfer control in next line.
new Memory allocate operator.
delete Memory release operator.

C++ Scope Resolution Operator

Blocks and scopes can be used in constructing programs. The same variable name can be used to have different meanings in differnt blocks. The scope of the variable extends from the point of its declaraton till the end of the block containing the declaration. A variable declared inside a block is said to be local.

In C, the global version of a variable cannot be accessed within the inner block. C++ resolves this problem by introducing a new operator ::(scope resolution operator). This operator allows access to the global variable.

Example 1: Access global variable using Scope resolution operator.


int a=100;
void main()
    int a=10;
        cout<<a<<endl; //local variable
        cout<<::a; //global variable
Related Topic:
C Language Operators — check it out!