ProgrammingHardCapgemini · Cognizant GenC Next
What will be the output of the following pseudocode? (AND has higher precedence than OR)
What will be the output of the following pseudocode? (AND has higher precedence than OR)
Integer a = 5, b = 2, c = 3
if (a > b OR b > c AND c > a)
Print a + b + c
else
Print a - b - c
end if- A. 0
- B. 30
- C. 7
- D. 10
Correct answer: D. 10
AND binds tighter than OR, so the test is (a > b) OR (b > c AND c > a) = true OR false = true, and 10 is printed. Reading it left to right as (a > b OR b > c) AND c > a gives false and the trap 0.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? Integer calls = 0 Function f(Integer m, Integer n) calls = calls + 1 if (m == 0 OR n…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer a = 1, b = 100, steps…
- What will be the output of the following pseudocode? Integer a[5] = {7, 7, 5, 7, 6} Integer m1 = -1, m2 = -1 for (each i from 0 to 4) if…
- What will be the output of the following pseudocode? Integer a[5] = {2, 3, 4, 5, 1}, passes = 0, n = 5 Boolean swapped for (each i from 0…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 77, steps = 0, p…
- What will be the output of the following pseudocode? (<< is left shift, | is bitwise OR, & is bitwise AND) Integer x = 0 for (each i from…