Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the value of the following expression?

i = 1;
i << 1 < 1>

  • A.2
  • B.-2
  • C.1
  • D.-1

Answer: A

Correct answer: 2

<< shifts the bits left, and one place left doubles the value:

\[ 1 \ll 1 = 1 \times 2^1 = 2 \]

The value of the expression is therefore 2. Shifting cannot produce a negative result here, since the sign bit of a small positive int is nowhere near the top.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.