Question 41
MediumWhat will be printed by the following pseudocode?
Integer x = 0, i
for (each i from 0 to 4)
if (i mod 2 == 0)
x = x | (1 << i)
end if
end for
Print x
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 printed by the following pseudocode?
Integer x = 0, i
for (each i from 0 to 4)
if (i mod 2 == 0)
x = x | (1 << i)
end if
end for
Print x
31
15
21
10
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Integer n = 29
n = n & ~(1 << 2)
Print n
33
29
21
25
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Integer n = 22
Print n & (-n)
4
2
22
1
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Integer a[5] = {6, 3, 6, 9, 3}
Integer r = 0, i
for (each i from 0 to 4)
r = r ^ a[i]
end for
Print r
6
27
0
9
Sign up free to see the answer and a step-by-step explanation.
What is the output of this pseudocode?
Integer x = 13, r = 0, i
for (each i from 1 to 4)
r = (r << 1) | (x & 1)
x = x >> 1
end for
Print r
14
11
13
7
Sign up free to see the answer and a step-by-step explanation.
What is the output of this pseudocode?
Integer n = 10
Print n ^ (n >> 1)
15
10
5
0
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Integer a = 6, b = 11, d = a ^ b, c = 0
while (d > 0)
c = c + (d & 1)
d = d >> 1
end while
Print c
13
4
3
2
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Integer x = 1, i
for (each i from 1 to 5)
x = (x << 1) + 1
end for
Print x
64
63
31
32
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Integer n = 37
if ((n >> 3) & 1)
Print "bit 3 set"
else
Print "bit 3 clear"
end if
bit 3 clear
bit 3 set
8
error
Sign up free to see the answer and a step-by-step explanation.
What is the output of this pseudocode?
Integer a = 5, b = 3
Print (a & b) + (a | b), a + b
6 8
7 8
8 8
8 7
Sign up free to see the answer and a step-by-step explanation.