Algoritma & Pemrograman 01 Operators For Fundamental Types v1.1
Algoritma & Pemrograman 01 Operators For Fundamental Types v1.1
Prepared by
Frans Panduwinata, S.Kom, M.T
Binary Operator and Operands
Binary Arithmetic Operators
Binary Arithmetic Operators (cont)
• The sign operator (–) returns the value of the operand but
inverts the sign.
EXAMPLE:
int n = –5; cout << -n; // Output: 5
• EXAMPLE:
int result;
result = length + 1 == limit;
If the condition index < max is not met, the program will not attempt
to read a number!
Operands and Order of Evaluation (cont)
EXERCISE 1
What values do the following arithmetic expressions have?
d. 3 + 4 % 5 e. 3 * 7 % 4 f. 7 % 4 * 3
Exercises (cont)
EXERCISE 2
a. How are operands and operators in the following expression
associated?
x = –4 * i++ – 6 % 4;
EXERCISE 3
The int variable x contains the number 7. Calculate the value of the
following logical expressions:
b. !x && x >= 3
c. x++ == 8 || x == 7
Exercises (cont)
EXERCISE 4
What screen output does the
program generate?
Examine the results!