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

Discussion

In case of ordinary int variables

  • A.leftmost bit is reserved for sign
  • B.rightmost bit is reserved for sign
  • C.no bit is reserved for sign
  • D.none of these

Answer: A

Correct answer: leftmost bit is reserved for sign

A plain int is signed, and in the two's complement representation used by essentially every current implementation the most significant - leftmost - bit carries the sign: 0 for non-negative, 1 for negative.

That bit is not available for magnitude, which is why a 32-bit int spans roughly \( -2^{31} \) to \( 2^{31}-1 \) rather than 0 to \( 2^{32}-1 \). Declaring the variable unsigned releases the bit for magnitude and doubles the positive range.

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

Post your comment

Please log in or register to post a comment.