Scroll to Top

Interview Questions and Answers in C

C Programming Questions and Answers – Bitwise Operators – 1

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

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

#include <stdio.h>
int main()
{
int c = 2 ^ 3;
printf(“%d\n”, c);
}
a) 1
b) 8
c) 9
d) 0

Answer: a
Explanation: None.

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

#include <stdio.h>
int main()
{
unsigned int a = 10;
a = ~a;
printf(“%d\n”, a);
}
a) -9
b) -10
c) -11
d) 10

Answer: c
Explanation: None.

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

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

Answer: c
Explanation: None.

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

#include <stdio.h>
int main()
{
int a = 2;
if (a >> 1)
printf(“%d\n”, a);
}
a) 0
b) 1
c) 2
d) No Output

Answer: c
Explanation: None.

5. Comment on the output of the following C code.

#include <stdio.h>
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
Explanation: None.

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

#include <stdio.h>
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
Explanation: None.

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

#include <stdio.h>
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
Explanation: None.

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

#include <stdio.h>
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
Explanation: None.

« Prev – C Programming Questions and Answers – Increment and Decrement Operators – 2
» Next – C Programming Questions and Answers – Bitwise Operators – 2

 

Related posts

Leave a Comment

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

Scroll to Top
%d bloggers like this: