250+ TOP MCQs on Bitwise Operators and Answers

’s MCQs on C helps anyone preparing for placement in HCL and other companies. Anyone looking for HCL placement papers should practice these questions continuously for 2-3 months, thereby ensuring a top position in placements.

Here is a listing of C questions on “Bitwise Operators” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int a = 5, b = -7, c = 0, d;
  5.         d = ++a && ++b || ++c;
  6.         printf("n%d%d%d%d", a, b, c, d);
  7.     }

a) 6 -6 0 0
b) 6 -5 0 1
c) -6 -6 0 1
d) 6 -6 0 1
Answer: d
Clarification: None.

2. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int a = -5;
  5.         int k = (a++, ++a);
  6.         printf("%dn", k);
  7.     }

a) -3
b) -5
c) 4
d) Undefined
Answer: a
Clarification: None.

3. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2;
  5.         x = x << 1;
  6.         printf("%dn", x);
  7.     }

a) 4
b) 1
c) Depends on the compiler
d) Depends on the endianness of the machine
Answer: a
Clarification: None.

4. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = -2;
  5.         x = x >> 1;
  6.         printf("%dn", x);
  7.     }

a) 1
b) -1
c) 2 31 – 1 considering int to be 4 bytes
d) Either -1 or 1
Answer: b
Clarification: None.

5. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         if (~0 == 1)
  5.             printf("yesn");
  6.         else
  7.             printf("non");
  8.     }

a) yes
b) no
c) compile time error
d) undefined
Answer: b
Clarification: None.

6. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = -2;
  5.         if (!0 == 1)
  6.             printf("yesn");
  7.         else
  8.             printf("non");
  9.     }

a) yes
b) no
c) run time error
d) undefined
Answer: a
Clarification: None.

7. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int y = 0;
  5.         if (1 |(y = 1))
  6.             printf("y is %dn", y);
  7.         else
  8.             printf("%dn", y);
  9.  
  10.     }

a) y is 1
b) 1
c) run time error
d) undefined
Answer: a
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int y = 1;
  5.         if (y & (y = 2))
  6.             printf("true %dn", y);
  7.         else
  8.             printf("false %dn", y);
  9.  
  10.     }

a) true 2
b) false 2
c) either true 2 or false 2
d) true 1
Answer: a
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *