Here it is:
a) Dividing two int
s performs integer division always. So the result of a/b
in your case can only be an int
.
If you want to keep a
and b
as int
s, yet divide them fully, you must cast at least one of them to double: (double)a/b
or a/(double)b
or (double)a/(double)b
.
b) c
is a double
, so it can accept an int
value on assignement: the int
is automatically converted to double
and assigned to c
.
c) Remember that on assignement, the expression to the right of =
is computed first (according to rule (a) above, and without regard of the variable to the left of =
) and then assigned to the variable to the left of =
(according to (b) above). I believe this completes the picture.