ProgrammingModerateAmazon OA · TCS NQT
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer a[7] = {4, 1, 2, 1, 2, 5, 4}
Integer x = 0
for (each i from 0 to 6)
x = x ^ a[i]
end for
Print x- A. 19
- B. 5
- C. 0
- D. 4
Correct answer: B. 5
XOR cancels equal pairs (v ^ v = 0) and is order-free, so the pairs 4, 1, 2 vanish and the single unpaired 5 remains.
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 a = 29, b = 15, x, c = 0 x = a ^ b while (x > 0) c = c + (x & 1) x = x >> 1…
- What will be the output of the following pseudocode? (integers are two's complement; ~ is bitwise NOT; >> is an arithmetic shift that…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 19, steps = 0, s…
- What will be the output of the following pseudocode? Integer u[1..10], i2 = 1, i3 = 1, i5 = 1, nx u[1] = 1 for (each k from 2 to 10) nx =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 50, lo = 0, hi =…
- What will be the output of the following pseudocode? (operands are evaluated left to right; arrays are indexed from 0) Integer q[5], front…