What is the difference between signed and unsigned int

前端 未结 5 729
闹比i
闹比i 2020-11-30 18:46

What is the difference between signed and unsigned int?

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 19:08

    In practice, there are two differences:

    1. printing (eg with cout in C++ or printf in C): unsigned integer bit representation is interpreted as a nonnegative integer by print functions.
    2. ordering: the ordering depends on signed or unsigned specification.

    this code can identify the integer using ordering criterion:

    char a = 0;
    a--;
    if (0 < a)
        printf("unsigned");
    else
        printf("signed");
    

提交回复
热议问题