LearnFrenzy
Sign in Take a free test

Bitwise Operators · Exercise 1 of 4

Bitwise Operators Bitwise Operators MCQ

  • 12 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twelve multiple-choice questions on the bitwise operators, masks, shifts and their undefined cases, precedence, integer promotion and C23 literals. Pick an option to check your answer instantly.

Question 1 Easy

What is the value of 5 & 3?

A 1
B 7
C 6
D 8
Question page & discussion
Question 2 Easy

For any integer x, what is x ^ x?

A x
B 0
C 1
D 2 * x
Question page & discussion
Question 3 Easy

Which expression is 1 when bit k of an unsigned x is set, and 0 otherwise?

A x & k
B (x >> k) & 1u
C x | (1u << k)
D x ^ k
Question page & discussion
Question 4 Easy

Which statement clears bit k of x and leaves every other bit unchanged?

A x |= 1u << k;
B x &= ~(1u << k);
C x ^= 1u << k;
D x &= 1u << k;
Question page & discussion
Question 5 Easy

When is x << 1 equal to x * 2?

A Always, for every int
B For unsigned x (modulo 2ⁿ), and for non-negative signed x whose result fits
C Never
D Only for odd x
Question page & discussion
Question 6 Medium

For a 32-bit unsigned x, what is x << 32?

A 0
B x
C Undefined behaviour
D UINT_MAX
Question page & discussion
Question 7 Medium

What does the C standard say about -16 >> 2?

A It is always 4
B It is implementation-defined; GCC and Clang give -4
C It is a compile error
D It is always 0
Question page & discussion
Question 8 Hard

What is -1 << 1 according to the C standard?

A -2
B 0xFFFFFFFE
C Undefined behaviour
D Implementation-defined
Question page & discussion
Question 9 Medium

How does C parse x & 1 == 0?

A (x & 1) == 0
B x & (1 == 0)
C It is a syntax error
D (x == 0) & 1
Question page & discussion
Question 10 Easy

What is the value of ~0u on a system with 32-bit unsigned int?

A 0
B 1
C 4294967295 (UINT_MAX)
D -1
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links