8. Type Conversions
 
When variables are promoted to higher precision, data is preserved. This is automatically done by the    compiler for mixed data type expressions.
int i;
float f;
f=i +3.14159; / * i is promoted to float , f=(float)i+3.14159 * /
Another conversion done automatically by the compiler is ’char’ → ’int’. This allows comparisons as    well as manupilations of character variables.
isupper =(c>=’A’ && c<=’Z’)?1:0;
                              /* c and literal constants are converted to int */
if (!isupper )      c=c−’a’+’A’;
                             /* subtraction is possible because of integer conversion */
As a rule (with exceptions), the compiler promotes each term in an binary expression to the highest    precision operand.
 
 
이전페이지 / 9 / 다음페이지