Shortend operator
It is combination of arithmetic operator and assignment
operator.
There are five shortend operators:
Let value of a is 12….
Shortend operator |
Without Shortend
operator |
With Shortend operator |
Output |
|
|
|
|
+= |
a=a+5 |
a+=5 |
17 |
-= |
a=a-5 |
a-=5 |
7 |
*= |
a=a*5 |
a*=5 |
60 |
/= |
a=a/5 |
a/=5 |
2.4 |
%= |
a=a%5 |
a%=5 |
2 |
Unary operator
there are two unary operator :-
i)
Increment operator (++)
ii)
Decrement operators(--)
i) Increment operator :- this operator increase the value of variable by 1 .
ii) decrement operator:- this decrease the value of
variable by 1.
Syntax:
a=10;
a++;
cout<<a;--------Γ 11
a=20;
a--;
cout<<a;--------Γ 19
Note :
It means the value of variable can be changed either using
assignment operator or using unary operator.
types of increment
and decrement operator:-
i) Prefix
ii) postfix
0 Comments