Operators
C-language operators are explained in Chapter 6, “Operators.”
An “operand” is a constant or variable manipulated by an operator in an expression. An “operator” specifies how the operands in an expression are to be evaluated. Operators also produce a result that can be nested within a larger expression.
C provides a rich set of operators covering everything from basic arithmetic operations to logical and bitwise operations. You can also combine the assignment operator (=) with any arithmetic or bitwise operator to form a combined assignment operator.
C operators have two properties, precedence and associativity. You can change the normal order of evaluation by enclosing expressions in parentheses.
Table 0.3 lists the C operators and their precedence and associativity values. The lines in the table separate precedence levels. The highest precedence level is at the top of the table.
Table 0.3 C Operators
Symbol |
Name or Meaning |
Associativity |
( ) |
Function call |
Left to right |
[ ] |
Array element , |
|
. |
Structure or union member |
|
–> |
Pointer to structure member |
|
–– |
Decrement |
Right to left |
++ |
Increment , |
|
:> |
Base operator |
Left to right |
! |
Logical NOT |
Right to left |
~ |
One's complement , |
|
– |
Unary minus , |
|
+ |
Unary plus , |
|
& |
Address , |
|
* |
Indirection , |
|
sizeof |
Size in bytes , |
|
(type) |
Type cast [for example, (float) i] , |
|
* |
Multiply |
Left to right |
/ |
Divide , |
|
% |
Modulus (remainder), |
|
+ |
Add |
Left to right |
– |
Subtract , |
|
<< |
Left shift |
Left to right |
>> |
Right shift , |
|
< |
Less than |
Left to right |
<= |
Less than or equal to , |
|
> |
Greater than , |
|
>= |
Greater than or equal to , |
|
== |
Equal |
Left to right |
!= |
Not equal , |
|
& |
Bitwise AND |
Left to right |
^ |
Bitwise exclusive OR |
Left to right |
| |
Bitwise OR |
Left to right |
&& |
Logical AND |
Left to right |
|| |
Logical OR |
Left to right |
? : |
Conditional |
Right to left |
= |
Assignment |
Right to left |
*=, /=, %=, +=, –=, <<=, >>=, &=, ^=, |= |
Compound assignment |
|