Question 71
HardWhat will be the output of the following pseudocode?
Integer a = 12, b = 10
a = a ^ b
b = a ^ b
a = a ^ b
Print a, b, 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
a = a ^ b
b = a ^ b
a = a ^ b
Print a, b, a & b
6 6 6
10 12 6
10 12 8
12 10 8
Sign up free to see the answer and a step-by-step explanation.
What is the output of this pseudocode?
Integer s = 0, i
for (each i from 1 to 16)
if ((i & (i - 1)) == 0)
s = s + i
end if
end for
Print s
31
15
30
16
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Integer n = 13, ans = 0, bit = 1
while (n > 0)
if ((n & 1) == 0)
ans = ans | bit
end if
bit = bit << 1
n = n >> 1
end while
Print ans
15
2
1
13
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Integer x = 5, i
for (each i from 1 to 3)
x = (x << 1) ^ i
end for
Print x
45
43
40
47
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Integer n = 255
Integer h = (n >> 4) & 15, l = n & 15
Print h, l, (l << 4) | h
16 15 255
15 0 15
15 15 240
15 15 255
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Integer n = 200
Integer c = 0
while ((n & 1) == 0)
n = n >> 1
c = c + 1
end while
Print c, n
4 12
3 50
2 50
3 25
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Integer a = 7, b = 2
Print a << b, a >> b, (a & 1) == 1, (a | b) - (a & b)
28 1 true 9
14 3 true 5
28 1 true 5
28 1 false 5
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Integer cnt = 0, x
for (each x from 0 to 15)
if ((x ^ (x >> 1)) == 6)
cnt = x
end if
end for
Print cnt
4
3
6
5
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Integer s = 0, mask
for (each mask from 0 to 15)
Integer bits = 0, t = mask
while (t > 0)
bits = bits + (t & 1)
t = t >> 1
end while
if (bits == 2)
s = s + 1
end if
end for
Print s
4
16
6
8
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Integer n = 22
Print n & 1, (n >> 1) & 1, (n >> 2) & 1, (n >> 3) & 1, (n >> 4) & 1
0 1 1 0 0
0 1 1 0 1
1 0 1 1 0
1 1 0 1 0
Sign up free to see the answer and a step-by-step explanation.