Gentlemen, I apologize for maybe a stupid question, and even ask it - what happens if you add a double and an int?
Thank you in advance)))
Gentlemen, I apologize for maybe a stupid question, and even ask it - what happens if you add a double and an int?
Thank you in advance)))
when adding int and double, the result is double, because double has a larger range than int. In your case, you put the result (which, once again, is of type double) in an integer variable. Of course, int cannot store floating point numbers, so a rounded number will be stored in b. and the number will be 9, not 0, as you indicated. Example
Here is a crib that where and how you can bring (took Horstmann):
- solid line - lossless conversion.
- dash - when casting losses are possible.
in other cases, an explicit cast (in parentheses) is required.

When added, it will be double. If I remember correctly, in arithmetic operations, if at least one operand is of the double type, the other operands are given in double and as a result the double is output. Correct me if I'm wrong.
Source: https://ru.stackoverflow.com/questions/319094/
All Articles