在研究C转换时,我发现了一段关于Integer晋升的文章,我还不太明白,它说:
"Integer types smaller than int are promoted when an operation is performed on them. If all values of the original type can be represented as an int, the value of the smaller type is converted to an int; otherwise, it is converted to an unsigned int"
考虑到:
问题是:为什么小于int的类型不应该用int表示?为什么一个无符号int可以表示一个int不应该表示的值?
提前谢谢。
发布于 2012-04-26 07:32:21
虽然short
的等级比int
低,但它可以是相同的大小(以位为单位),例如16位系统上的sizeof(int) == sizeof(short) == 2
。因此,unsigned short
可能能够保存大于INT_MAX
的值。
对于您问题的第二部分,这个部分的答案大致相同:unsigned int
可以保存不能用int表示的值,即INT_MAX+1
。UINT_MAX
。
https://stackoverflow.com/questions/10336543
复制相似问题