ProgrammingModerateInfosys · Wipro pattern
What will be the output of the following pseudocode? (&, |, ^ are bitwise AND, OR, XOR; << is a left shift; precedence as in C: << binds tighter than &, which binds tighter than ^, then |.)
What will be the output of the following pseudocode? (&, |, ^ are bitwise AND, OR, XOR; << is a left shift; precedence as in C: << binds tighter than &, which binds tighter than ^, then |.)
Integer a = 12, b = 10 Print (a & b) + (a | b), a ^ b << 1
- A. 22 24
- B. 22 12
- C. 14 24
- D. 22 6
Correct answer: A. 22 24
12 = 1100, 10 = 1010: AND = 1000 = 8, OR = 1110 = 14, sum 22 (always equal to a + b). In a ^ b << 1 the shift happens first: b << 1 = 20 = 10100, and 01100 ^ 10100 = 11000 = 24. Doing the XOR first gives (12 ^ 10) << 1 = 6 << 1 = 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? Function f(Integer n) if (n <= 1) return 1 end if return f(n - 1) + 2 f(n - 2) End…
- What will be the output of the following pseudocode? (Strings are indexed from 0.) String s = "PSEUDOCODE" Integer v = 0 for (i = 0 to…
- What will be the output of the following pseudocode? Integer x = 1 for (k = 1 to 10) x = (x 3) mod 7 end for Print x
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[5] = {3, 1, 4, 1, 5} for (i = 1 to 4) arr[i]…
- What will be the output of the following pseudocode? (calls counts every call, including the first; mod is the remainder.) Integer calls =…
- What will be the output of the following pseudocode? (& is bitwise AND.) Integer total = 0 for (i = 1 to 15) Integer n = i while (n != 0)…