data structures using type conversion and typecasting type conversion or typecasting of variables refers to changing variable of one data type into another while type conversion is done implicitlycasting has to be done explicitly by the programmer we will discuss both these concepts here type conversion type conversion is done when the expression has variables of different data types so to evaluate the expressionthe data type is promoted from lower to higher level where the hierarchy of data types can be given asdoublefloatlongintshortand char for exampletype conversion is automatically done when we assign an integer value to floating point variable consider the following codefloat xint ynowx as integer value is automatically converted into its equivalent floating point representation typecasting typecasting is also known as forced conversion it is done when the value of one data type has to be converted into the value of another data type the code to perform typecasting can be given asfloat salary int salsal (intsalarywhen floating point numbers are converted to integersthe digits after the decimal are truncated thereforedata is lost when floating point representations are converted to integral representations as we can see in the codetypecasting can be done by placing the destination data type in parentheses followed by the variable name that has to be converted hencewe conclude that typecasting is done to make variable of one data type to act like variable of another type programming example write program to convert an integer into the corresponding floating point number #include #include int main(float f_numint i_numclrscr()printf("\ enter any integer")scanf("% "&i_num)f_num (float)i_numprintf("\ the floating point variant of % is % "i_numf_num)return output enter any integer the floating point variant of is www allitebooks com