Define Implicit and Explicit type of Conversion
Implicit Type Conversions
- A narrowing conversion is one that converts an object to a type that cannot include all of the values of the original type e.g., float to int
- A widening conversion is one in which an object is converted to a type that can include at least approximations to all of the values of the original type
e.g., int to float
- A mixed-mode expression is one that has operands of different types
- Coercion is an implicit type conversion
- Disadvantage of coercions:
-They decrease in the type error detection ability of the compiler
- In most languages, all numeric types are coerced in expressions, using widening conversions
Explicit Type Conversions
- Called casting in C-based language
- Examples
C: (int) angle
Ada: Float (sum)
- Note that Ada’s syntax is similar to function calls
- A narrowing conversion is one that converts an object to a type that cannot include all of the values of the original type e.g., float to int
- A widening conversion is one in which an object is converted to a type that can include at least approximations to all of the values of the original type
e.g., int to float
- A mixed-mode expression is one that has operands of different types
- Coercion is an implicit type conversion
- Disadvantage of coercions:
-They decrease in the type error detection ability of the compiler
- In most languages, all numeric types are coerced in expressions, using widening conversions
Explicit Type Conversions
- Called casting in C-based language
- Examples
C: (int) angle
Ada: Float (sum)
- Note that Ada’s syntax is similar to function calls
Implicit and Explicit type of Conversion
Reviewed by MCH
on
March 01, 2014
Rating:
No comments: