Bitwise Operators – C Programming Interview Questions and Answers

C Programming-Bitwise Operators


Question 1
What is the output of this C code?
#include 
int main()
{
int c = 2 ^ 3;
printf("%d\n", c);
}
A
1
B
8
C
9
D
0
Question 2
What is the output of this C code?
#include 
int main()
{
unsigned int a = 10;
a = ~a;
printf("%d\n", a);
}
A
-9
B
-10
C
-11
D
10
Question 3
What is the output of this C code?
#include 
int main()
{
if (7 & 8)
printf("Honesty");
if ((~7 & 0x000f) == 8)
printf("is the best policy\n");
}
A
Honesty is the best policy
B
Honesty
C
is the best policy
D
No output
Question 4
What is the output of this C code?
#include 
int main()
{
int a = 2;
if (a >> 1)
printf("%d\n", a);
}
A
0
B
1
C
2
D
No Output.
Question 5
Comment on the output of this 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
Question 6
What is the output of this 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
Question 7
What is the output of this 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
Question 8
What is the output of this 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
Question 9
What is the output of this C code?
#include 
void main()
{
int a = 5, b = -7, c = 0, d;
d = ++a && ++b || ++c;
printf("\n%d%d%d%d", a, b, c, d);
}
A
6 -6 0 0
B
6 -5 0 1
C
-6 -6 0 1
D
6 -6 0 1
Question 10
What is the output of this C code?
#include 
void main()
{
int a = -5;
int k = (a++, ++a);
printf("%d\n", k);
}
A
-3
B
-5
C
4
D
Undefined
Question 11
What is the output of this C code?
#include 
int main()
{
int x = 2;
x = x << 1;
printf("%d\n", x);
}
A
4
B
1
C
Depends on the compiler
D
Depends on the endianness of the machine
Question 12
What is the output of this C code?
#include 
int main()
{
int x = -2;
x = x >> 1;
printf("%d\n", x);
}
A
1
B
-1
C
2 ^ 31 – 1 considering int to be 4 bytes
D
Either b or c
Question 13
What is the output of this C code?
#include 
int main()
{
if (~0 == 1)
printf("yes\n");
else
printf("no\n");
}
A
yes
B
no
C
Compile time error
D
Undefined
Question 14
What is the output of this C code?
#include 
int main()
{
int x = -2;
if (!0 == 1)
printf("yes\n");
else
printf("no\n");
}
A
yes
B
no
C
Run time error
D
Undefined
Question 15
What is the output of this C code?
#include 
int main()
{
int y = 0;
if (1 |(y = 1))
printf("y is %d\n", y);
else
printf("%d\n", y);
}
A
1
B
0
C
Run time error
D
Undefined
Question 16
What is the output of this C code?
#include 
int main()
{
int y = 1;
if (y & (y = 2))
printf("true %d\n");
else
printf("false %d\n");
 }
A
true 2
B
false 2
C
Either option a or option b
D
true 1

Check Your Answers:

  1. A
  2. C
  3. C
  4. C
  5. B
  6. A
  7. D
  8. C
  9. D
10. A
11. A
12. A
13. C
14. A
15. A
16  C





SHARE

Unknown

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment