4.4 类型转换

from http://www.learncpp.com/cpp-tutorial/44-type-conversion-and-casting/

类型隐式转换

类型隐式转换的步骤如下所示:

Long double (highest)
Double
Float
Unsigned long int
Long int
Unsigned int
Int (lowest)

最底层是int而不是short或是char,是因为char和short在求值时会被扩展为int。

隐式转换会出现一些有趣的问题,如5u - 10。也许你会认为结果是-5.但是10为int型,发生隐式转换成unsigned int型,因此最后结果为unsigned int型,2^32 - 5。又如float fValue = 10/4;

posted @ 2012-05-22 20:44  grassofsky  阅读(159)  评论(0编辑  收藏  举报