ProgrammingModerateTCS NQT · Accenture pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer x = 5, y = 9 x = x ^ y // ^ is bitwise XOR y = x ^ y x = x ^ y Print x, y, (5 & 9), (5 | 9)
- A. 9 5 1 13
- B. 9 5 0 14
- C. 5 9 1 13
- D. 9 5 1 14
Correct answer: A. 9 5 1 13
Three XORs swap the values: x = 9, y = 5. 5 = 0101 and 9 = 1001 share only bit 0, so 5 & 9 = 1 and 5 | 9 = 1101 = 13 (5 ^ 9 would be 12).
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 Function f(Integer n) if (n <= 0) return 0 return (n mod 10) + f(n / 10) //…
- What will be the output of the following pseudocode? Integer c = 0 for (i = 1 to 100) if ((i mod 3 == 0) OR (i mod 5 == 0)) if (NOT (i mod…
- What will be the output of the following pseudocode? Integer a[] = {5, 3, 8, 1, 9, 2} Integer m1 = -1, m2 = -1 for (each x in a) if (x >…
- What will be the output of the following pseudocode? Integer Function fun(Integer a, Integer b) if (b == 0) return 1 if (b mod 2 == 0)…
- What will be the output of the following pseudocode? Integer n = 45, c = 0 while (n != 0) c = c + (n & 1) n = n >> 1 end while Print c
- What will be the output of the following pseudocode? Integer x = 10, s = 0 while (x > 0) s = s + x x = x - 3 end while Print s, x