operator in c++

Operator In C++ programming Language-: C++ also  support a rich set of built in operator we have already used several of them such as equal to add(+)Minus(-)  multiplication(*) and division(/) operator is a symbol that tells the computer to perform certain mathematics or logical manipulation. operators are used in program to manipulate data and variables. they usually form a part of mathematical or logical expression.

ANSCI C operators can be classified into in number of category  these are here:

  1. arithmetic operators-
  2. relation operators
  3.  logical operators
  4. assignment operators
  5. increment and decrements operators
  6. condition operators
  7. Bitwise operators
  8. . Special operators

All the C programming language operator are use in c++ also . Others new operator are here

: :             Scope Resolution Operator

:  : *          pointer to member declarator

->*            Point to member operator

.*               Point to member operator

Delete     memory release operator

End1       line feed operator

New         Memory allocation operator

Setw         Field with operator


c++ operators


Scope Resolution  Operators in C++ -: We know that the C++ has a block structure language. Block and constant can be used in constructing program. We know that the same variable name can be used to have different meaning in different block.The scope of the variable extends from the point of its declaration til of the end of the block containing the declaration. A variable declare inside a block is said to be local to that block. For example

  int x=10;
   int x=1;

For this example here we see the two value are for X it can not accessed from with the inner block. For resolving the problem c++ introduce a new operator : : scope resolution operator.

example of scope resolution operator with a program

# include <iostream> 

using namespace std;

int m=10;   //global m

     int m=20;


           int k=m;

           int m=30;
          cout <<"we are in inner block \n";

          cout <<"k= " << k <<"\n";

           cout <<"m= " << m <<"\n";

          cout <<" :: m= " << ::m <<"/n";
 cout <<"/n we are in outer block \n";

 cout <<"m= "<< m << "\n";

 cout <<":: m=" << :: m <<"\n";

 return 0;



The output of this program.

We are inner block



:: m=10

we are in outer block



In the above program the variable m is declared at three place namely outside the main () function , inside the main () function and the inside the inner block.

Member dereferencing operator in c++ -:  C++ provide a set of three pointer to member operator. these are the

:  : *          pointer to member declarator—-:To declare a pointer to a member of class.

->*            Point to member operator—-:To access a member using object name and a pointer to that member.

.*               Point to member operator—: To access a member using a pointer to the object and a pointer to a member.

Memory management operator -: c use malloc() and callock() function  to allocate memory dynamically at run time. In the c++ language two unary operator New and delete that perform the task of allocating and freeing the memory in better and easier way. Since these operators manipulated memory on the free store so  these called free store operators.

An object can be created by new and the destroyed by delete .

pointer variable = new datatype;  // for creating a object

for a example

int * p = new int(25);

float * q= new float (8.2);


Delete pointer example

delete pointer variable ;  // for release memory or delete 


Manipulators operators in c++-: These operators that are used to format the data display. The most commonly used manipulators are end1 and setw. for example


cout <<"m= " << m << end1;

     <<"n =" << n << end1;



Type cast operators in c++-:  This is permits explicit conversion of variable or expression using the type cast operator.  For example

type name (expression)

for example

average = sum/(float)i;     // c notation 

average =sum/float(i);      // c++ notation

The function call notation usually leads to simplest expression. c++ adds the cast operators.


Leave a Comment