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

Discussion

The value of n after this runs is

int8_t n = 127;
n++;

  • A.0
  • B.undefined in principle, and \( -128 \) on most implementations
  • C.128
  • D.127

Answer: B

Signed overflow is undefined, so nothing is guaranteed, although two's complement hardware almost always produces minus 128. Writing code that depends on it is what makes a program fragile under a change of compiler or optimisation level.

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

Post your comment

Please log in or register to post a comment.