type castingimplicit type conversions as allowed


Type Casting

Implicit type conversions, as allowed by the language, can lead to errors creeping in the program if care is not taken. Thus, explicit type conversions may be used in mixed mode expressions. This is done by type-casting a value of a certain type, into the desired type. This is done by using the (type) operator as follows:

                (type) expression

expression is changed to the given type by the rules stated above.

e.g.

float a = 10.0, b = 3.0, c;

c = a / b;

This expression will result in 3.333333 being stored in 'c'. If the application needs integer division of two floating point numbers, then the following expression with the type cast can be used:

                c = (int)a / (int)b;

                                or

                c = (int) (a / b);

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: type castingimplicit type conversions as allowed
Reference No:- TGS0309257

Expected delivery within 24 Hours