What is the difference between signed and unsigned variables?

后端 未结 8 1057
一个人的身影
一个人的身影 2020-12-07 13:04

I have seen these mentioned in the context of C and C++, but what is the difference between signed and unsigned variables?

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 13:41

    Signed variables use one bit to flag whether they are positive or negative. Unsigned variables don't have this bit, so they can store larger numbers in the same space, but only nonnegative numbers, e.g. 0 and higher.

    For more: Unsigned and Signed Integers

提交回复
热议问题