High-level Programming Language (Pascal)
Arithmetic Expressions in Pascal
- similar to the mathematical expressions
- an expression can be a constant, a variable or a combination of constants, variables and operators
- a list of mathematical operators and Pascal operators is shown below :
|
Mathematical Operator
|
Pascal Operator
|
Operation
|
Example
|
Result
|
|
+
|
+
|
Addition |
3+2
|
5
|
|
-
|
-
|
Subtraction |
3-2
|
1
|
|
-
|
-
|
Unary Minus |
-3
|
-3
|
|
×
|
*
|
Multiplication |
3*2
|
6
|
|
÷
|
/
|
Real Division |
5/2
|
2.5
|
|
÷
|
div
|
Integer Division |
5 div 2
|
2
|
|
mod
|
mod
|
Modulo (remainder) |
5 mod 2
|
1
|
- the order of precedence
|
Level of Precedence
|
Arithmetic Operator
|
|
highest
|
( )
|
|
high
|
- (unary minus)
|
|
low
|
*, /, mod, div
|
|
lowest
|
+, - (subtraction)
|
|