The word cast is used in the sense of “casting into a mold.” The
compiler will automatically change one type of data into another if
it makes sense. For instance, if you assign an integral value to a
floating-point variable, the compiler will secretly call a function (or
more probably, insert code) to convert the int to a float. Casting
allows you to make this type conversion explicit, or to force it when
it wouldn’t normally happen.
To perform a cast, put the desired data type (including all
modifiers) inside parentheses to the left of the value. This value canbe a variable, a constant, the value produced by an expression, or
the return value of a function. Here’s an example:
from:<Thinking in C++>
本文探讨了编程中类型转换的概念,特别是编译器如何自动进行类型转换以及如何使用显式强制转换来确保数据类型的准确转换。通过具体示例说明了如何执行显式强制类型转换。
1066

被折叠的 条评论
为什么被折叠?



