当前位置: 代码迷 >> 综合 >> Casting operator
  详细解决方案

Casting operator

热度:19   发布时间:2023-12-21 21:36:28.0

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 can 
be 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++>



  相关解决方案