ProgrammingHardInfosys · Capgemini pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer x = 182 // binary 1011 0110, 8-bit register Print x >> 2, (x << 1) & 255, x & (-x)
- A. 45 364 2
- B. 91 108 2
- C. 45 108 2
- D. 45 108 4
Correct answer: C. 45 108 2
182 >> 2 = 45 (drop two bits). x << 1 = 364, and & 255 keeps the low 8 bits: 364 − 256 = 108. x & −x isolates the lowest set bit, 0000 0010 = 2.
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 a, Integer b) if (a == 0) return b return f(b mod a, a)…
- What will be the output of the following pseudocode? Integer a[] = {4, 7, 1, 9, 3} for (i = 0 to 3) if (a[i] > a[i + 1]) swap(a[i], a[i +…
- What will be the output of the following pseudocode? Integer n = 5, s = 0 for (i = 1 to n) for (j = 1 to i) if ((i + j) mod 2 == 0) s = s…
- What will be the output of the following pseudocode? Integer v = 1 for (k = 0 to 4) v = v 2 + k end for Print v
- What will be the output of the following pseudocode? Integer calls = 0 Integer Function f(Integer n) calls = calls + 1 if (n <= 2) return…
- What will be the output of the following pseudocode? Integer a = 5, b, c, d b = a++ // post-increment c = ++a // pre-increment d = a + b +…