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?