TYPE CASTING/TYPE CONVERSION :
An expression may contain variables and constants of different types. C works with six data types namely int, unsigned int, long, int, float, double and long double to perform all arithmetic operations. In general, the lower type is promoted to the higher type before the operation proceeds so that no data is lost. This data type conversion is performed both explicitly and implicitly. The automatic conversion of data in intermix data type operation such that no data is lost is called as automatic type conversion or implicit data type conversion.
The following rules are used for the implicitly conversion of real and integer values:
a. An arithmetic operation between an integer and integer always yields an integer result.
b. Operation between a real and real always yields a real value.
c. Operation between an integer and real always yields a real value.
A part from automatic type conversion, we need to force a type conversion. For this purpose casting are used. The process of casting has a local effect. The general form of a casting is:
(type_name) expression;
0 comments:
Post a Comment