Type Conversion And Coercion:
Explicit Type Conversion: Routines to change from data type to another.
Example:
Pascal: The function 'round'- converts a real type to integer
C: eg(int)x, for float x converts the value of x to type integer.
Coercion: Implicit type of conversion, performed by the system.
Pascal: + integer and real, integer is converted to real.
Java: Permits implicit coercion if operation is widening.
C Explicit cast must be given.
Two opposite approaches to type coercion:
• No Coercion, any type mismatch is considered an error, pascal, Ada.
• Coercion are the rule: Only if no conversion is possible, error is reported.
Advantages of Coercion:
It basically free the programmer from the low level concerns upto some level. as Adding two different data types i.e Real & int
Disadvantage of Coercion :
As programmer concerned to some level is reduced which may be that it hides some serious errors which will not be easy to point out.