Operators and Expressions 45
Table 3.2 Arithmetic operators
Arithmetic Operators
Operator Explanation
Examples
+ Addition 2+2=4
-
Subtraction 5-3=2
*
Multiplication
2*5=10
/
Division
10/2=5
%
Modular Division 11%3=2 (Remainder 2)
b) Unary Operators Unary operators are increment operator (++), decrement (- -) and minus
(-). These operators and their descriptions are given in the Table 3.3.
Table 3.3 Unary arithmetic operators
Operator Description or Action
-
Minus
++ Increment
—
Decrement
&
Address Operator
Size of
Gives the size of operator
a ) M inus ( - ) Unary minus is used to indicate or change the algebraic sign of a value.
For Example
int x= -50;
int y= -x;
Assigns the value of -50 to x and the value of -50 to y through x. The - sign used in this way is
called the unary operator because it takes just one operand. There is no unary plus (+) in C. Even
though, a value assigned with plus sign is valid. For example int x=+50; here + is valid but in practice
this sign should not be attached in C.
b) Increment (++) & Decrement (- -) Operators The C compilers produce very fast,
efficient object codes for increment and decrement operations. This code is better than generated by
using the equivalent assignment statement. So, increment and decrement operators should be used
whenever possible.
The operator++ adds one to its operand. Whereas the operator - - subtracts one from its operand.
For justification x=x+l can be written as x++; and x = x -l; can be written as x - - ;. Both these
operators may either follow or precede the operand. That is, x=x+1; can be represented as x++; or
++x;
If ++ or — are used as a suffix to the variables name then the post increased/decreased operations
take place. Consider an example for understanding ++ operator as a suffix to the variable.