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 | "~" is available in version 4.53 or later |
! | logical negation | available in version 4.53 or later | |
+ | 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 | available in version 4.54 or later |
>>> | logical shift | available in version 4.54 or later | |
5 | and & | bitwise conjunction | "&" is available in version 4.53 or later |
6 | xor ^ | bitwise exclusive disjunction | "^" is available in version 4.53 or later. |
7 | or | | bitwise disjunction | "|" is available in version 4.53 or later. |
8 | < > <= >= | relational | |
9 | = == <> != | relational | "==" and "!=" are available in version 4.54 or later. |
10 | && | logical conjunction | version 4.53 or later. |
11, low | || | logical disjunction | version 4.53 or later. |
"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.