Expressions and operators
Expressions consist of constants, variables, operators, and parentheses. Constants and variables must be of the integer type. The value of an expression is also an integer.
The value of a relational expression (formed using relational operators) is 1,
if it is true, or 0 if false.
The following are operators:
| Precedence | Operators | Category | Note |
|---|---|---|---|
| 1, high | not ~ | bitwise negation | |
| ! | logical negation | ||
| + | plus unary | ||
| - | minus unary | ||
| 2 | * | multiplication | |
| / | division | ||
| % | remainder | the value of expression A % B is the remainder of A / B. | |
| 3 | + | addition | |
| - | subtraction | ||
| 4 | >> << | arithmetic shift | |
| >>> | logical shift | ||
| 5 | and & | bitwise conjunction | |
| 6 | xor ^ | bitwise exclusive disjunction | |
| 7 | or | | bitwise disjunction | |
| 8 | < > <= >= | relational | |
| 9 | = == <> != | relational | |
| 10 | && | logical conjunction | |
| 11, low | || | logical disjunction |
"and", "or", "xor" and "not" are bitwise operator, not logical operator.
Example:
1 + 1
4 - 2 * 3 The value is -2.
15 % 10 The value is 5.
3 * (A + 2) A is an integer variable.
A and not B
A <= B A and B are integer variables. The value is 1,
if the expression is true, or 0 if false.