有符号/无符号字符之间的区别 [英] Difference between signed / unsigned char
问题描述
所以我知道 signed int
和 unsigned int
之间的区别在于,一个位用于表示数字是正数还是负数,但这是如何实现的适用于 char
?一个字符怎么可能是积极的或消极的?
So I know that the difference between a signed int
and unsigned int
is that a bit is used to signify if the number if positive or negative, but how does this apply to a char
? How can a character be positive or negative?
推荐答案
C 语言中没有专门的字符类型".char
是整数类型,与 int
、short
和其他整数类型相同(在这方面).char
恰好是最小的整数类型.因此,就像任何其他整数类型一样,它可以是有符号或无符号的.
There's no dedicated "character type" in C language. char
is an integer type, same (in that regard) as int
, short
and other integer types. char
just happens to be the smallest integer type. So, just like any other integer type, it can be signed or unsigned.
确实(顾名思义)char
主要用于表示字符.但是 C 中的字符由它们的整数代码"表示,因此整数类型 char
用于实现该目的这一事实并没有什么不寻常的.
It is true that (as the name suggests) char
is mostly intended to be used to represent characters. But characters in C are represented by their integer "codes", so there's nothing unusual in the fact that an integer type char
is used to serve that purpose.
char
和其他整数类型唯一的一般区别是纯 char
不是 signed char
的同义词,而与其他整数类型signed
修饰符是可选的/隐含的.
The only general difference between char
and other integer types is that plain char
is not synonymous with signed char
, while with other integer types the signed
modifier is optional/implied.
这篇关于有符号/无符号字符之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!