As studied earlier, Operators are the symbols, which performs operations on various data items known as operands. For Example: in a a+b
, a
and b
are operands and +
is an operator.
Note:- To perform an operation, operators and operands are combined together forming an expression. For example, to perform an addition operation on operands a and b, the addition(+) operator is combined with the operands a and b forming an expression.
C has two very usefull operators.
They are increment(++) and decrement(--) operators. The increment operator(++) adds 1 to the operator value contained in the variable.
The decrement operator(--) subtracts 1 from the value contained in the variable.
Increment operator can be used in two way pre-increment(++a) and post-increment(a++).
Similarly decrement operator can also be used in two way pre-increment(--a) and post-increment(a--).
Expression | Description | Example | End result |
---|---|---|---|
A++ | Add 1 to a variable agrer use. | int A=10,B; B=A++ |
A=11 B=10 |
+AA | Add 1 to a variable before use. | int A=10,B; B=++A; |
A=11 B=11 |
A-- | Subtract 1 from a variable after use. | int A=10,B; B=A--; |
A=9 B=10 |
--A | Subtract 1 from a variable before use. | int A=10,B; B=--A; |
A=9 B=9 |
10 10 11 10 11 11