Download presentation
Presentation is loading. Please wait.
1
Assignment statement and Arithmetic operation 2
+–×÷ Expressions and Operations
2
Expression Y A+B ; := NO, this is an EXPRESSION Let’s consider the
following statement. Y A+B ; := Is it an EQUATION?
3
Expression OPERATOR ; A+B := Y OPERANDS
4
Expression Expression looks like a mathematical expression.
The computer first evaluate the expression and the result will be stored in the variable on the left hand side
5
3+4+5 A+B*C/D (A+B)*(A+B)/(B-C) A*X*X+B*X+C Pi*RADIUS*RADIUS
Here are some examples of expressions: 3+4+5 A+B*C/D (A+B)*(A+B)/(B-C) A*X*X+B*X+C Pi*RADIUS*RADIUS 4*A*A-Pi*A*A A+(N-1)*D
6
Addition + integer + integer => integer real + integer => real
integer + real => real real + real => real
7
Subtraction – integer - integer => integer
real - integer => real integer - real => real real - real => real
8
Multiplication * integer * integer => integer
real * integer => real integer * real => real real * real => real
9
Real Division / integer / integer => real real / integer => real
real / real => real
10
Integer operations (DIV and MOD)
Quotient 5 3 16 15 1 Remainder 16 MOD 3
11
Integer Division integer DIV integer => integer
real DIV integer => NOT ALLOWED integer DIV real => NOT ALLOWED real DIV real => NOT ALLOWED
12
Modulo integer MOD integer => integer
real MOD integer => NOT ALLOWED integer MOD real => NOT ALLOWED real MOD real => NOT ALLOWED
13
Exercise 2 If A, B, C are integer variables, and D, E, F are real variables, which of the following statements are invalid? 1. C:=A+B-C VALID 2. C:=D+E-F; INVALID 3. A:=C/B - C/B; INVALID 4. E:=(A+B) / (A+B) VALID 5. D:= D DIV D INVALID 6. A:= A MOD A VALID 7. D:=A+A+B+B+C+C; VALID
14
A := 3 + 4 * 5; Precedence Please consider the following Add statement
or Multiply first? A := * 5;
15
Precedence ( ) - (unary minus) * , / , MOD, DIV +, -
In PASCAL, the precedence is: ( ) - (unary minus) * , / , MOD, DIV +, -
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.