Question 1
EasyWhat will be the output of the following pseudocode?
Integer a = 12, b = 10
Print a & b
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Pseudocode and Output Prediction
What will be the output of the following pseudocode?
Integer a = 12, b = 10
Print a & b
2
8
6
14
Answer: B
12 = 1100 and 10 = 1010. AND keeps bits set in both: 1000 = 8.
What will be the output of the following pseudocode?
Integer a = 12, b = 10
Print a | b
22
14
6
8
Answer: B
1100 OR 1010 = 1110 = 14.
What will be the output of the following pseudocode?
Integer a = 12, b = 10
Print a ^ b // ^ is XOR
14
6
2
8
Answer: B
1100 XOR 1010 = 0110 = 6.
What will be the output of the following pseudocode?
Integer x = 3
Print x << 3
11
6
24
9
Answer: C
Shifting left by 3 multiplies by 2³ = 8: 3 × 8 = 24.
What will be the output of the following pseudocode?
Integer x = 100
Print x >> 2
98
25
50
400
Answer: B
Shifting right by 2 divides by 4 (dropping any remainder): 25.
What will be the output of the following pseudocode?
Integer x = 9
if (x & 1)
Print "Odd"
else
Print "Even"
end if
1
9
Odd
Even
Answer: C
The lowest bit of 9 (1001) is 1, so x & 1 is 1 (true): odd.
What will be the output of the following pseudocode?
Integer x = 7
Print x ^ x
0
14
7
1
Answer: A
Any number XOR itself is 0.
What is the output of this pseudocode?
Print 12 & 10
6
14
2
8
Answer: D
1100 & 1010 = 1000, which is 8.
What will be printed by the following pseudocode?
Print 12 | 10
22
8
14
6
Answer: C
1100 | 1010 = 1110, which is 14.
What is the output of this pseudocode?
Print 12 ^ 10
8
2
6
14
Answer: C
^ is XOR: 1100 ^ 1010 = 0110, which is 6.