C – explanation for this answer [on hold]

  • A+
int main(void) {      float w = 8.456;     int b = 3;      printf("%d", (int)(b * w));      return 0; } 

Can't seem to understand how does this equal to 25, even though it's int * float and is displayed as an int, and what does int means in printf line... Isn't int multiply by float a 0?


b*w result is a float (=25.368) then you cast it to an int and it is truncated to 25.

If you were expecting the result to be 24, both variable should be ints.

See: c-language data type arithmetic rules


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: