Which conversions take place when evaluating the following expressions?
char cval;
int ival;
float fval;
// Assume all 3 have been set to correct values...
a) if(fval)
b) double dval = fval + ival;
c) dval + ival + cval;
My thoughts:
a) I assume if needs a bool value, so the float gets implicitly casted to bool.
b) I assume that fval is promoted to double and ival is converted to a double, and then they are added.
c) First, ival is converted to a double. Then dval + ival gets evalutated, which is of type double. Then cval…I don’t know if it gets converted to double directly, or if it it is promoted to int first. Anyway, after that step the temp value dval + ival is added to that double.
Is my understanding correct?
a)
fvalis contextually converted tobool.In cases
bandc, the “usual arithmetic conversions” apply, meaning:b)
ivalis converted tofloatand (using a special rule, rather than the “usual arithmetic conversions“)fval + ivalis converted todouble.c)
ivalis converted todouble,cvalis converted todouble.