home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 170_01 / typeconv.c < prev    next >
Text File  |  1979-12-31  |  2KB  |  46 lines

  1. /* 
  2. ** Demonstration of Type Conversion 
  3. ** across assignments. 
  4. */ 
  5. main() 
  6.     { 
  7.     char c1,c2,c3; 
  8.     int i1,i2,i3; 
  9.     float f1,f2,f3; 
  10.  
  11.     c1 = 'x';    /* no conversion */ 
  12.     c2 = 1000;    /* int constant demoted to char */ 
  13.     c3 = 6.02e23;    /* float constant demoted to char */ 
  14.     printf("%c  %c  %c\n",c1,c2,c3); 
  15.  
  16. /* Note that the character value is printed as is; the integer 
  17. ** with a value of 1000 is converted to its binary equivalent 
  18. ** of 1111101000 and truncated to the first 8 data bits which 
  19. ** gives 11101000 or decimal 232 or the Greek symbol "phi" 
  20. ** when the ASCII symbol is printed; and the conversion from 
  21. ** float to char is meaningless and does not occur.  */ 
  22.  
  23.     i1 = 'x';    /* char constant promoted to int */ 
  24.     i2 = 1000;    /* no conversion */ 
  25.     i3 = 6.02e23;    /* float constant demoted to int */ 
  26.     printf("%d  %d  %d\n",i1,i2,i3); 
  27.  
  28. /* Note that ASCII 'x' has an integer value of 120, and the  
  29. ** character constant 'x' is promoted when we assign it to an 
  30. ** integer.  The floating point constant is demoted to the  
  31. ** largest integer 32767 that is possible in the Microsoft 
  32. ** C compiler and that number is returned as an integer. */ 
  33.  
  34.     f1 = 'x';    /* x char constant promoted to float */ 
  35.     f2 = 1000;    /* int constant promoted to float */ 
  36.     f3 = 6.02e23;    /* no conversion */ 
  37.     printf("%f %f %f\n",f1,f2,f3); 
  38.  
  39. /* There are no demoted values, everything is represented as 
  40. ** its double precision floating point equivalent!   */
  41.  
  42.     }
  43. ; 
  44.  
  45. /* There are no demoted values, everything is represented as 
  46. ** its double preci