ProgrammingHardCapgemini · Infosys pattern
What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right shifts.)
What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right shifts.)
Integer x = 5, y = 7 x = x ^ y y = y & x x = x | y Print x, y
- A. 7 5
- B. 2 2
- C. 7 2
- D. 2 7
Correct answer: B. 2 2
x = 101 ^ 111 = 010 = 2. y = 7 & 2 = 2. x = 2 | 2 = 2. This looks like the XOR swap but uses & and |, so it is NOT a swap. Assuming a swap gives 7 5.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- How many numbers are printed when fun(5) is called? Function fun(Integer n) if (n <= 0) return end if fun(n - 1) Print n fun(n - 2) End…
- What will be the output? (A static variable keeps its value between calls and is initialised only once. The two calls in Print are…
- What will be the output of the following pseudocode? Integer a = 1, b = 2, c = 3 a = b + c b = a - b c c = a b - c Print a + b + c
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer s = 0 for (each i…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer n = 100, c = 0, d = 5…
- What will be the output? (calls counts every call, including the first.) Integer calls = 0 Function fun(Integer a, Integer b) calls =…