C++: Small Topics

Operators in C++
     <<      insertion operator
     >>      extraction operator
     ::         Scope resolution operator
     ::*      Pointer to member declarator
     ->*     Pointer to member operator
     .*       Pointer to member operator
  delete  Memory release operator
   endl     line feed operator
   new      Memory allocation operator
   setw     Field width operator

Memory Management Operators

pointer-variable = new data-type;

The new operator allocates sufficient memory to hold a data object of type data-type and returns the address of the object.

pointer-variable = new data-type(value);

pointer-variable = new data-type[size];

delete pointer-variable;

The pointer-variable is the pointer that points to a data object created with new.

delete[size] pointer-variable;


Manipulators are operators that are used to format the data display.

endl and setw are manipulators.

Type Cast Operator

type-name (expressioin)

eg.    average=sum/float(i);

Operator Overloading

Overloading means assigning different meanings to an operation,depending on the context.
Eg. of operator overloading

The operator * when applied to a pointer variable, gives the value pointed to by the pointer.But it is also commonly used for multiplying two numbers.

                      < Happy Coding >


In Association with Amazon.in