variables - K&R C Chapter exercise int to float? -


section 1.3 of kernighan , ritchie uses following temperature conversion program introduce statements:

#include <stdio.h>  /* print fahrenheit-celsius table */  int main(){          int fahr;         (fahr = 0; fahr <= 300; fahr = fahr + 20)             printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32)); } 

what doesn't explain how program can make use of int variable produce float values without error. makes valid? don't variables in equation have of same type? i'm hesitant move forward without understanding this.

the conversion implicit, enabling warnings should give message explaining int being converted double.

here (5.0/9.0)*(fahr-32)), double being multiplied int, , int converted double using usual arithmetic conversions.

the types in arithmetic don't have match. c has whole chapter dedicated conversions: 6.3 conversions, 6.3.1 arithmetic operands.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -