My question: why the following can also compile?
Int I=(int) (10.0/5), I think there is something wrong with the 10.0/5 or in counting, belong to the type double to 10.0 strong around alone, but why is ok? Compile without question, the output is correct
thank you
CodePudding user response:
After duoble type divided by five is duoble type, and receive value is an int type, this is an error, int I=(int) (10.0/5) in this step you speak of type int value transformation, not an error, this transformation as the results will be lost behind the decimal valuesCodePudding user response:
Small type conversion for large type for implicit conversion, can automatically turn, while large type into small type need to specify the transformation type, otherwise you won't receive, int I=(int) (10.0/5), computing result for double, receiving type to int, you need to type coercion, type won't be able to receive, and turn you doubt the operation of belong to small to big, do not need to display the specified,CodePudding user response:
It is the result of the operation was a double 2.0CodePudding user response:
Thank you for reply to youCodePudding user response:
Strong, show that is okCodePudding user response:
The above I asked I want to ask:10.0/5: this form is a double type divided by an integer type, it is ok? Of course the result is a double type, the number of different types of operation what are the rules?
Must be int I=1 + 2 we know that 1 and 2 are int type is ok, the 10.0/5 in 10.0 as the appearance of the floating-point defaults to double type, then why not int? Though he looks like a double type
Thank you
CodePudding user response: