Hardware Reference
In-Depth Information
if (i . 0 && i , 10)
statement 2 ;
// if 0 , i , 10 then execute statement 2
if (a1 55 a2)
statement 3 ;
// if a1 equals a2 then execute statement 3
5.3.7 Precedence of Operators
Precedence refers to the order in which operators are processed. C language maintains a
precedence for all operators, shown in Table 5.1. Operators at the same level are evaluated from
left to right. A few examples that illustrate the precedence of operators are listed in Table 5.2.
Precedence
Operator
Associativity
Highest
( ) [ ] .
! , ++ - - + - * & (type) sizeof
*/%
+ -
<< >>
< <= > >=
== !=
&
^
|
&&
||
?:
= += - = *= /= %= &= ^= |= <<= >>=
'
left to right
right to left
left to right
left to right
left to right
left to right
left to right
left to right
left to right
left to right
left to right
left to right
right to left
right to left
left to right
Lowest
Table 5.1 Table of precedence of operators
Expression
Result
Note
15 - 2 * 7
(13 - 4) * 5
(0x20 | 0x01) != 0x01
0x20 | 0x01 != 0x01
1 << 3 + 1
(1 << 3) + 1
1
45
1
0x20
16
9
* has higher precedence than +
!= has higher precedence than |
+ has higher precedence than <<
Table 5.2 Examples of operator precedence
5.4 Control Flow
Control-flow statements specify the order in which computations are performed. In C lan-
guage, the semicolon is a statement terminator. Braces { } are used to group declarations and
statements together into a compound statement, or block, so that they are syntactically equiv-
alent to a single statement.
 
Search WWH ::




Custom Search