Question 61
HardWhat does the following pseudocode print?
Integer n = 0, i
for (each i from 0 to 7)
if (i mod 3 == 0)
n = n | (1 << i)
end if
end for
Print n, n & (n - 1)
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 does the following pseudocode print?
Integer n = 0, i
for (each i from 0 to 7)
if (i mod 3 == 0)
n = n | (1 << i)
end if
end for
Print n, n & (n - 1)
73 73
9 8
73 64
73 72
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Integer x = 0b10110100
Integer c = 0
while (x != 0)
x = x & (x - 1)
c = c + 1
end while
Print c
3
4
8
5
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Integer a = 29, b = 15
Integer s = a, carry = b
while (carry != 0)
Integer t = s & carry
s = s ^ carry
carry = t << 1
end while
Print s
14
40
18
44
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Integer n = 37, r = 0, i
for (each i from 0 to 7)
r = (r << 1) | ((n >> i) & 1)
end for
Print r
164
82
37
73
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Integer x = 6
Integer y = x & (-x)
Integer z = x | (x + 1)
Integer w = x ^ (x >> 1)
Print y, z, w
6 7 5
2 7 3
2 7 5
2 13 5
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Integer a[7] = {4, 1, 2, 1, 2, 4, 9}
Integer r = 0, i
for (each i from 0 to 6)
r = r ^ a[i]
end for
Print r, r ^ 9
0 9
23 14
9 9
9 0
Sign up free to see the answer and a step-by-step explanation.
What is the output of this pseudocode?
Integer mask = 0, i
Integer s[5] = {3, 1, 4, 1, 5}
for (each i from 0 to 4)
mask = mask | (1 << s[i])
end for
Integer c = 0
while (mask > 0)
c = c + (mask & 1)
mask = mask >> 1
end while
Print c
3
4
5
6
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Integer n = 10, i, total = 0
for (each i from 0 to (1 << 3) - 1)
if ((i & 1) == 1 and (i & 4) == 0)
total = total + i
end if
end for
Print total
6
16
4
10
Sign up free to see the answer and a step-by-step explanation.
What is the output of this pseudocode?
Integer x = 0xF0, y = 0x3C
Print x & y, x | y, x ^ y, (x ^ y) >> 2
48 252 204 50
48 252 60 51
48 252 204 51
60 240 204 51
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Integer n = 100, p = 1
while (p < n)
p = p << 1
end while
Print p, p >> 1
256 128
64 32
128 64
100 50
Sign up free to see the answer and a step-by-step explanation.