Test automatic type conversions - C Data Type

C examples for Data Type:Type Cast

Description

Test automatic type conversions

Demo Code

#include <stdio.h>

int main(void){
    char ch;// ww  w .  j a v  a2  s .co m
    int i;
    float fl;
    
    fl = i = ch = 'C';                                  
    printf("ch = %c, i = %d, fl = %2.2f\n", ch, i, fl); 
    ch = ch + 1;                                        
    i = fl + 4 * ch;                                    
    fl = 2.0 * ch + i;                                  
    printf("ch = %c, i = %d, fl = %2.2f\n", ch, i, fl); 
    ch = 107;                                          
    printf("Now ch = %c\n", ch);                        
    ch = 81.89;                                         
    printf("Now ch = %c\n", ch);                        
    
    return 0;
}

Result


Related Tutorials