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

Discussion

The value of c after this runs on a target with 32-bit int is

uint8_t a = 200, b = 100;
uint8_t c = (a + b) / 2;

  • A.0
  • B.300
  • C.150
  • D.22

Answer: C

Both operands are promoted to int before the addition, so the sum is 300 with no wrap and the division gives 150, which fits in a byte. Had the arithmetic been done in eight bits the sum would have wrapped to 44 and the answer would have been 22.

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

Post your comment

Please log in or register to post a comment.