In this blog |
---|
TYPE CONVERSION AND TYPE CASTING |
TYPE CONVERSION
type conversion is done when in an expression we are having different data types ,eg..
char c;
int i;
float j;
double e;
(c+i)*(j/e);
in the above expression we are having different types of data so type conversion would be done according to figure 1 ,data would be converted from lower level to higher level...
figure 1 |
above eg is converted as follows
(NOTE: when you are having an assignment statement in an expression then after evaluating the expression data type of expression is converted to type of variable we are assigning)
TYPE CASTING
type casting is also converting the data from 1 type to another but type conversion is done by compiler but type casting is done by programmer only ,eg..
int a;
(float)a
(data type) expression
this would convert and integer data to float data
(NOTE: always convert the lower level data to higher level data as it would prevent from loosing the data)
No comments:
Post a Comment