Variable name and scope 1

Variable name and scope 2

Variable name and scope 3

Arithmetic operator 1

Arithmetic operator 2

Relational Operators - 1

Relational Operators - 2

Logical Operators - 1

Logical Operators - 2

Assignment Operator - 1

Assignment Operator - 2

Increment Decrement Operator - 1

Increment Decrement Operator - 2

Conditional Operator - 1

Conditional Operator - 2

sizeof operator - 1

sizeof operator - 2

Bitwise operator - 1

Bitwise operator - 2

Operator precedence and associativity - 1

Operator precedence and associativity - 2

Operator precedence and associativity - 3

if statement - 1

if statement - 2

if else - 1

if else - 2

switch statement - 1

switch statement - 2

for loop - 1

for loop - 2

while loop - 1

while loop - 2

do while loop - 1

do while loop - 2

break and continue - 1

break and continue - 2

pointer - 1

pointer - 2

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 &

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.

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

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.

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? #include<stdio.h> 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

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)

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

b) false

c) Syntax Error

d) Runtime Error