问题描述
什么是铸造,什么是铸造类型?
这是一个通用的铸造,
加宽转换是从一种类型转换为另一种类型,其中目标类型具有比源更大的范围或精度int到long,float到double)。 缩小转换是完全相反的(长到int)。
内置原语之间的扩展转换是隐式的,这意味着您不必使用cast操作符指定新类型,除非您希望在计算期间将类型视为较宽的类型。默认情况下,类型转换为在二进制表达式或赋值的变量一侧使用的最宽实际类型,而不计算另一侧的任何类型。)
缩小转换,另一方面,必须显式转换,并且必须处理溢出异常,除非代码被标记为未检查溢出(C#中的关键字未选中; I不知道它是否为该语言所独有)
difference between widening and narrowing in c++?what is mean by casting and what is types of casting?
This is a general casting thing, not C++ specific.
A "widening" cast is a cast from one type to another, where the "destination" type has a larger range or precision than the "source" (e.g. int to long, float to double). A "narrowing" cast is the exact opposite (long to int). A narrowing cast introduces the possibility of overflow.
Widening casts between built-in primitives are implicit, meaning you do not have to specify the new type with the cast operator, unless you want the type to be treated as the wider type during a calculation. By default, types are cast to the widest actual type used on the variable's side of a binary expression or assignment, not counting any types on the other side).
Narrowing casts, on the other hand, must be explicitly cast, and overflow exceptions must be handled unless the code is marked as not being checked for overflow (the keyword in C# is unchecked; I do not know if it's unique to that language)
这篇关于c ++中加宽和缩小的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!