Char is unsigned, short is signed.
So while they are both 2-byte long, they use the sixteenth bit for different purposes.
The range of the char type is 0 to 2^16 - 1 (0 to 65535).
The short range is -2^15 to 2^15 - 1 (−32,768 to 32,767).
char和short在内存中所占大小一样,都是16位。但是short有一位符号位。所以范围是0 ~ 2^16 - 1 (0 ~ 65535)。而char没有符号位。所以char的范围是-2^15 ~ 2^15 - 1 (−32,768 ~ 32,767).
网友评论