ProgrammingModerateAccenture · Cognizant pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer a = 5, b = 0
if (a > 3 && b != 0)
Print "X"
else if (a > 3 || b > 0)
Print "Y"
else
Print "Z"
end if- A. XY
- B. Z
- C. Y
- D. X
Correct answer: C. Y
&& needs both parts true, but b != 0 is false, so X is skipped. || needs only one part true, and a > 3 is true, so Y is printed.
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? Function fun(Integer n) if (n < 3) return n end if return fun(n - 1) + 2 fun(n - 3)…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? Integer x = 0 for (each i from 1 to 5) for (each j from 1 to i) if ((i + j) mod 2 ==…
- What will be the output of the following pseudocode? Function fun(Integer n) if (n > 0) fun(n - 1) Print n fun(n - 1) end if End Function…
- What will be the output of the following pseudocode? Integer a = 1, b = 1, c for (each i from 1 to 6) c = a + b a = b b = c end for Print b