ProgrammingModerateAccenture · Cognizant pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer a = 13, b = 10 // 1101 and 1010 Print a & b, a | b, a ^ b, ~a // 32-bit two's complement
- A. 8 15 7 2
- B. 9 15 6 -14
- C. 8 15 7 -14
- D. 8 15 7 -13
Correct answer: C. 8 15 7 -14
1101 & 1010 = 1000 = 8; | = 1111 = 15; ^ = 0111 = 7. Bitwise NOT flips every bit, and in two's complement ~a = −a − 1 = −14 (not just the 4 visible bits, which would be 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 n) if (n == 0) return 0 return f(n / 2) 10 + (n mod 2) End…
- What will be the output of the following pseudocode? Stack st = empty for (each x in {3, 1, 4, 1, 5, 9, 2, 6}) while (st not empty AND…
- What will be the output of the following pseudocode? Integer a[] = {5, 1, 4, 2, 3}, c = 0 for (i = 0 to 4) for (j = i + 1 to 4) if (a[i] >…
- What will be the output of the following pseudocode? String s = "PROGRAM", r = "" for (i = length(s) - 1 down to 0 step 2) r = r + s[i]…
- What will be the output of the following pseudocode? Integer n = 5, t = 0 for (i = 1 to n) if (i mod 2 == 1) t = t + i i else t = t - i…
- What will be the output of the following pseudocode? Integer a = 1, b = 1, t for (k = 1 to 5) t = a + b a = b b = t if (b mod 2 == 0)…