C++ increment decrement operators


  • Increment operator (++) increases the value of its operand by 1
  • Decrement operator (--) decreases the value of its operand by 1
Example :

int  x;
int  y;

// Increment operators
x = 1;

y = ++x;    // x is now 2, y is also 2
y = x++;    // x is now 3, y is 2

// Decrement operators
x = 3;
y = x--;    // x is now 2, y is 3
y = --x;    // x is now 1, y is also 1

0 Comments