C Program to understand type conversion in assignment | Type conversion in C programming

Spread the love

 Program to understand type conversion in assignment :

  1. /* Program to understand type conversion in assignment*/
  2. #include<stdio.h>
  3. int main(void)
  4. {
  5.         char c1,c2;
  6.         int i1,i2;
  7.         float f1,f2;
  8.         c1=‘H’;  
  9.         i1=80.56;       /*float converted to int, only 80 assigned to i1  */
  10.         f1=12.6;
  11.         c2=i1;          /*int converted to char */
  12.         i2=f1;          /*float converted to int */
  13.         /*Now c2 has the character with ASCII value 80, i2 is assigned value 12 */
  14.         printf(“c2=%c,  i2=%dn,c2,i2);
  15.         f2=i1;                  /*int converted to float*/
  16.         i2=c1;                  /*char converted to int */
  17.         /*Now i2 contains ASCII value of character ‘H’ which is 72*/
  18.         printf(“f2=%.2f,  i2=%dn,f2,i2);
  19.         return 0;
  20. }

Venkatesh Macha

Hi Guys, I am Venkatesh Macha. I am a programmer and an Open Source enthusiast, Presently working as a Software Engineer. Apart from that, I love to explore new technologies and things.

You may also like...

Leave a Reply