ProgrammingHardInfosys · Wipro pattern
What will be the output of the following pseudocode? (&& binds more tightly than ||; ! is NOT.)
What will be the output of the following pseudocode? (&& binds more tightly than ||; ! is NOT.)
Integer a = 5, b = 10, c = 15
if (a > b || b < c && c > 20)
Print "X"
else if (!(a == 5) || c mod b == 5)
Print "Y"
else
Print "Z"
end if- A. Y
- B. X
- C. Z
- D. XY
Correct answer: A. Y
First condition: a > b is false, and b < c && c > 20 is true && false = false, so the whole || is false. Second: !(a == 5) is false, but 15 mod 10 = 5 is true → 'Y'. Dropping the && part and testing only a > b || b < c would wrongly print 'X'.
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? (/ is integer division.) Integer n = 6, steps = 0, peak = n while (n != 1) if (n mod…
- What will be the output of the following pseudocode? (reverse(x) returns x with its decimal digits reversed.) Integer n = 87, k = 0 while…
- What will be the output of the following pseudocode? Procedure fun(Integer n) if (n <= 0) return end if fun(n - 2) Print n fun(n - 1) End…
- What will be the output of the following pseudocode? (/ is integer division.) Integer a = 1, b = 100, steps = 0 while (a < b) a = a 2 b =…
- What will be the output of the following pseudocode? (calls counts every call, including the first; memo starts with every entry equal to…
- What will be the output of the following pseudocode? (/ is integer division.) Integer c = 0 for (n = 1 to 50) Integer d = 0 for (k = 1 to…