Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NET

C Programming Questions and Answers – Bitwise Operators

C Programming Questions and Answers – Bitwise Operators

 

1.What is the output of this C code?

 

#include <stdio.h>

int main()

{

int c = 2 ^ 3;

printf(“%d\n”, c);

}

a) 1

b) 8

c) 9

d) 0

View Answer

Answer:a

 

2.What is the output of this 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

View Answer

Answer:c

 

3.What is the output of this 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

 

View Answer

Answer:c

 

4.What is the output of this 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.

View Answer

Answer:c

 

5.Comment on the output of this 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

 

View Answer

Answer:b

 

6.What is the output of this 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

 

View Answer

Answer:a

 

7.What is the output of this 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

View Answer

Answer:d

 

8.What is the output of this 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

 

View Answer

Answer:c

 

9.What is the output of this 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

 

View Answer

Answer:d

 

10.What is the output of this 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

 

View Answer

Answer:a

 

11.What is the output of this 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

 

View Answer

Answer:a

 

12.What is the output of this 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 b or c

 

View Answer

Answer:b

 

13.What is the output of this 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

 

View Answer

Answer:b

 

14.What is the output of this 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

 

View Answer

Answer:a

 

15.What is the output of this 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

 

View Answer

Answer:a

 

16.What is the output of this 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 option a or option b

d) true 1

View Answer

Answer:c

Related Articles

Leave a Reply

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

Back to top button