Here is a listing of C Objective Questions on “Bitwise Operators” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include -
int main()
-
{ -
int c = 2 ^ 3;
-
printf("%dn", c);
-
}
a) 1
b) 8
c) 9
d) 0
Answer: a
Clarification: None.
2. What will be the output of the following C code?
-
#include -
int main()
-
{ -
unsigned int a = 10;
-
a = ~a;
-
printf("%dn", a);
-
}
a) -9
b) -10
c) -11
d) 10
Answer: c
Clarification: None.
3. What will be the output of the following C code?
-
#include -
int main()
-
{ -
if (7 & 8)
-
printf("Honesty");
-
if ((~7 & 0x000f) == 8)
-
printf("is the best policyn");
-
}
a) Honesty is the best policy
b) Honesty
c) is the best policy
d) No output
Answer: c
Clarification: None.
4. What will be the output of the following C code?
-
#include -
int main()
-
{ -
int a = 2;
-
if (a >> 1)
-
printf("%dn", a);
-
}
a) 0
b) 1
c) 2
d) No Output
Answer: c
Clarification: None.
5. Comment on the output of the following C code.
-
#include -
int main()
-
{ -
int i, n, a = 4;
-
scanf("%d", &n);
-
for (i = 0; i < n; i++)
-
a = a * 2;
-
}
a) Logical Shift left
b) No output
c) Arithmetic Shift right
d) Bitwise exclusive OR
Answer: b
Clarification: None.
6. What will be the output of the following C code?
-
#include -
void main()
-
{ -
int x = 97;
-
int y = sizeof(x++);
-
printf("x is %d", x);
-
}
a) x is 97
b) x is 98
c) x is 99
d) Run time error
Answer: a
Clarification: None.
7. What will be the output of the following C code?
-
#include -
void main()
-
{ -
int x = 4, y, z;
-
y = --x;
-
z = x--;
-
printf("%d%d%d", x, y, z);
-
}
a) 3 2 3
b) 2 2 3
c) 3 2 2
d) 2 3 3
Answer: d
Clarification: None.
8. What will be the output of the following C code?
-
#include -
void main()
-
{ -
int x = 4;
-
int *p = &x;
-
int *k = p++;
-
int r = p - k;
-
printf("%d", r);
-
}
a) 4
b) 8
c) 1
d) Run time error
Answer: c
Clarification: None.
