What is the actual use of “signed” keyword?

后端 未结 4 1293
逝去的感伤
逝去的感伤 2020-12-15 15:16

I know that unsigned integers are only positive numbers (and 0), and can have double the value compared to a normal int. Are there any difference between

in         


        
4条回答
  •  星月不相逢
    2020-12-15 15:32

    In the case of int, there's no difference. It only makes a difference with char, because

    1. it is not defined whether char is signed or unsigned, and
    2. char, signed char, and unsigned char are three distinct types anyway.

    So you should use signed if you need a signed char (which is probably rarely). Other than that, I can't think of a reason.

提交回复
热议问题