ProgrammingVery hardAccenture · Capgemini
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer x = 0, i
for (i = 1; i <= 10; i = i + 1)
x = ((x << 1) ^ i) & 15
end for
Print x
(<< is left shift, ^ is XOR, & is AND.)- A. 0
- B. 1
- C. 5
- D. 6
Correct answer: A. 0
x after each iteration (kept to 4 bits): 1, 0, 3, 2, 1, 4, 15, 6, 5, 0, so the final value is 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 w[5][5], i, j for (i = 0; i < 5; i = i + 1) for (j = 0; j < 5; j = j + 1) if…
- What will be the output of the following pseudocode? String A = "AXYT", B = "AYZX" Integer L[5][5] = all 0, i, j for (i = 1; i <= 4; i = i…
- What will be the output of the following pseudocode? Integer n = 9, steps = 0 while (n != 1) if (n mod 2 == 0) n = n / 2 else n = 3 n + 1…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer x, y Set x = 17, y =…
- What will be the output of the following pseudocode? Integer s = 0 for (each i from 1 to 10) if (i mod 2 == 0) s = s + i end if end for…
- What will be the output of the following pseudocode? Integer a = 6, b = 4 a = a + b b = a - b a = a - b Print a, b