What is the difference between signed and unsigned variables?

后端 未结 8 1054
一个人的身影
一个人的身影 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 14:03

    Unsigned variables can only be positive numbers, because they lack the ability to indicate that they are negative.

    This ability is called the 'sign' or 'signing bit'.

    A side effect is that without a signing bit, they have one more bit that can be used to represent the number, doubling the maximum number it can represent.

提交回复
热议问题