13. Conversions
explicit, and this determines whether an explicit cast is required.
[Example: For instance, the conversion
from type int to type long is implicit, so expressions of type int can
implicitly be treated as type long.
The opposite conversion, from type long to type int, is explicit and so an
explicit cast is required.
int a = 123;
long b = a; // implicit conversion from int to long
int c = (int) b; // explicit conversion from long to int
end example] Some conversions are defined by the language. Programs may
also define their own
conversions (§13.4).
explicit, and this determines whether an explicit cast is required.
[Example: For instance, the conversion
from type int to type long is implicit, so expressions of type int can
implicitly be treated as type long.
The opposite conversion, from type long to type int, is explicit and so an
explicit cast is required.
int a = 123;
long b = a; // implicit conversion from int to long
int c = (int) b; // explicit conversion from long to int
end example] Some conversions are defined by the language. Programs may
also define their own
conversions (§13.4).
博客介绍了C语言中的类型转换,包括隐式转换和显式转换。如从int到long是隐式转换,表达式可直接处理;从long到int则是显式转换,需显式强制类型转换。此外,语言本身定义了部分转换,程序也可自定义转换。
963

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



