Implicit Type Conversion: If one operand is short & the other is char, will char be converted to short?

半腔热情 提交于 2019-12-03 16:42:51

The "integer promotion" will convert both of them to int before the addition:

The following may be used in an expression wherever an int or unsigned int may be used:

— An object or expression with an integer type whose integer conversion rank is less than the rank of int and unsigned int.

[...] If an int can represent all values of the original type, the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions.

(ISO/IEC ISO/IEC 9899:1999 (E), §6.3.1.1)

According to the standard , short can never be defined using less number of bits than char. Therefore, x will indeed be converted to short.

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