Is char signed or unsigned by default?

前端 未结 7 795
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 06:49

In the book \"Complete Reference of C\" it is mentioned that char is by default unsigned.

But I am trying to verify this with GCC as well as Visual Stud

7条回答
  •  滥情空心
    2020-11-21 07:17

    The book is wrong. The standard does not specify if plain char is signed or unsigned.

    In fact, the standard defines three distinct types: char, signed char, and unsigned char. If you #include and then look at CHAR_MIN, you can find out if plain char is signed or unsigned (if CHAR_MIN is less than 0 or equal to 0), but even then, the three types are distinct as far as the standard is concerned.

    Do note that char is special in this way. If you declare a variable as int it is 100% equivalent to declaring it as signed int. This is always true for all compilers and architectures.

提交回复
热议问题