Please Turn On Java Script To Access This Site.

C Institute | Questions

Previous Topic : Bitwise operator - 1Next Topic : Operator precedence and associativity - 1

This section focuses on C interview questions, tricky questions, and puzzles, and viva questions based on “bitwise operator”. One shall practice these questions and puzzles to improve their C programming skills needed for various interviews (campus interviews, walk-in interviews, viva exams and company interviews), placements, entrance exams and other competitive exams. These programming questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate, engineering student, bca student, mca student, mcs students or an experienced IT professional. It will improve their understanding of C Language. Here is a listing of C questions and puzzles on “bitwise operator” along with answers and/or explanations.

Q1: Which of the following can have different meaning in different contexts?
a)  *
b)  &
c)  Neither * nor &
d)  Both * and &
Correct Answer : d
Explanation : ‘&’ can be used to get address of a variable and can also be used to do bitwise and operation.
Similarly ‘*’ can be used to get value at an address and can also be used to multiplication.

Q2: What does the following statement do?
a  = a | 1 << n;
a)  Toggles (n+1)th bit of x
b)  Unsets (n+1)th bit of x
c)  Sets (n+1)th bit of x
d)   Sets x as 2n
Correct Answer : c
Explanation : Let n be 4, the value of expression 1 << n would be 16 (In binary 00010000). If we do bitwise or of binary 00010000 with any number a would set its (n+1)th bit from left side.

Q3: What will be the output?
int main() 
  int x = 5,y = 6; 
  x = x^y; 
  y = x^y; 
  printf("%d %d",x,y); 
  return 0; 
a)  5 3
b)  3 5
c)  5 6
d)  6 5
Correct Answer : b
Explanation : ^ is bitwise xor operator.
x = 5 (101)
y = 6 (110)
x = x^y (101 ^ 110) = 3(011)
y = y^x (110 ^ 011) = 5(101)

Q4: #include<stdio.h>
int main()
	int x = 2;
	(x & 1) ? printf("true") : printf("false");
	return 0;
a)  true
b)  false
c)  Syntax Error
d)  Runtime Error
Correct Answer : b
Explanation : Learn bitwise & here

Previous Topic : Bitwise operator - 1Next Topic : Operator precedence and associativity - 1