C-programming - Increment decrement operator, C++ increment decrement operator

Increment decrement operator

Adding 1 to a variable is called incrementing and subtracting 1 from a variable is called decrementing. Incrementing or decrementing can be done only on integer values and not on floating point values.

Incrementing/decrementing can be done either before or an operation or after the operation and its named as prefix or postfix operation respectively.


include <iostream.h>
  void main( )
   {
      int i = 10, j=20;
      cout << "Result of increment operator"  << endl;
      cout << " i= " << i++ << endl;
      cout << " i= " << ++i << endl;
      cout << " i= " << i << endl;
      cout << " i= " << ++i << endl;
      cout << " i= " << i++ << endl;
      cout << endl;
      cout << "Result of decrement operator"  << endl;
      cout << " j= " << j-- << endl;
      cout << " j= " << --j << endl;
      cout << " j= " << j << endl;
      cout << " j= " << --j << endl;
      cout << " j= " << j-- << endl;
      cout << endl;


output


Result of increment operator
i= 10
i= 12
i= 12
i= 13
i= 13
i= 14
Result of decrement operator
j= 19
j= 19
j= 18
j= 18
j= 16
j= 16

The topic on C-programming - Increment decrement operator is posted by - Sathya

Hope you have enjoyed, C-programming - Increment decrement operatorThanks for your time

Tech Bluff