I am currently learning C and typecasts and it is suggesting that if I want to convert an int to a float I should precede the variable with (float)
to do this.
However, when I don't use the typecast, the answer still comes out correct, even though I am mixing the ints and floats.
Can someone explain why/when I would need to use the typecast (float)
in particular?
#include <stdio.h>
int main(void) {
int A, B, E;
float C, D;
A = 2;
B = 1;
C = 12.5;
D = C * A + B;
E = C * A + B;
printf("Total is %.1f\n", D);
printf("total is %d", E);
return 0;
}