Scroll to Top

HCL Placement Papers

C Programming Questions and Answers – Bitwise Operators – 2

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?

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

Answer: d
Explanation: None.

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

#include <stdio.h>
void main()
{
int a = -5;
int k = (a++, ++a);
printf(“%d\n”, k);
}
a) -3
b) -5
c) 4
d) Undefined

Answer: a
Explanation: None.

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

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

Answer: a
Explanation: None.

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

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

Answer: b
Explanation: None.

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

#include <stdio.h>
int main()
{
if (~0 == 1)
printf(“yes\n”);
else
printf(“no\n”);
}
a) yes
b) no
c) compile time error
d) undefined

Answer: b
Explanation: None.

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

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

Answer: a
Explanation: None.

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

#include <stdio.h>
int main()
{
int y = 0;
if (1 |(y = 1))
printf(“y is %d\n”, y);
else
printf(“%d\n”, y);

}
a) y is 1
b) 1
c) run time error
d) undefined

Answer: a
Explanation: None.

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

#include <stdio.h>
int main()
{
int y = 1;
if (y & (y = 2))
printf(“true %d\n”, y);
else
printf(“false %d\n”, y);

}
a) true 2
b) false 2
c) either true 2 or false 2
d) true 1

Answer: a
Explanation: None.

« Prev – C Programming Questions and Answers – Bitwise Operators – 1
» Next – C Programming Questions and Answers – Assignment Operators & Expressions – 1

Related posts

Leave a Comment

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

Scroll to Top
%d bloggers like this: