Signed to unsigned conversion in C - is it always safe?

前端 未结 8 1963
北荒
北荒 2020-11-22 01:55

Suppose I have the following C code.

unsigned int u = 1234;
int i = -5678;

unsigned int result = u + i;

What implicit conversions are goin

8条回答
  •  走了就别回头了
    2020-11-22 02:42

    When converting from signed to unsigned there are two possibilities. Numbers that were originally positive remain (or are interpreted as) the same value. Number that were originally negative will now be interpreted as larger positive numbers.

提交回复
热议问题