Why sizeof(int) is not greater than -1? [duplicate]

元气小坏坏 提交于 2019-11-27 09:47:48

Because sizeof(int) is unsigned. So -1 is converted to a large unsigned value.

Because sizeof yields a value of type size_t which is an unsigned type. In > expression usual arithmetic conversions will convert -1 to an unsigned type which is the type of the > result. The resulting value will be a huge positive value.

To get the expected behavior use:

(int) sizeof (int) > -1
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!