What is the difference between signed and unsigned variables?

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

    Signed variables can be 0, positive or negative.

    Unsigned variables can be 0 or positive.

    Unsigned variables are used sometimes because more bits can be used to represent the actual value. Giving you a larger range. Also you can ensure that a negative value won't be passed to your function for example.

提交回复
热议问题