1. Increment Operator ( ++ ):
The symbol ++ is used for incrementing the value by 1.
These are Two types
i) ++ identifier; This is also known as prefix increment.
ii) identifier ++; This is also known as postfix increment.
Eg:
1) int a=10;
++a; (or) a++;
a=11
2) int a=10,b;
b=++a;
a=11
b=11
3) int a=10,b;
b=a++;
a=11
b=10
2. Decrement Operator ( -- ):
The symbol -- is used for decrementing the value by 1.
These are Two types
i) -- identifier; This is also known as prefix decrement.
ii) identifier --; This is also known as postfix decrement.
Eg:
1) int a=10;
--a; (or) a--;
a=9
2) int a=10,b;
b=--a;
a=9
b=9
3) int a=10,b;
b=a--;
a=9
b=10
No comments:
Post a Comment