Home > Back-end >  I figured out the answer 6.5, consult a great god, and for explanation
I figured out the answer 6.5, consult a great god, and for explanation

Time:02-06

CodePudding user response:

Operation process is as follows
7/3=2//type int
2 * (int) (a + c)=2 * 7=14//type int
14/2=7//type int
7% 4=3//type int
2.5 + 3=5.5//float type

CodePudding user response:

When float and an int addition, automatic type conversion will happen? Float type into type int first? In the operation

CodePudding user response:

(int) (a + c) not convert float to an int?
Finally a + 3 is to convert 3 to float operation
Automatic type conversion occurs only in the two operands, not the whole expression
So
7/3 is int (because the two operands are int)
2 * (int) (a + c) is an int (because the result of a + c is converted to int)
14/2 is int
7% 4 is int
The last 2.5 + 3 is float
  • Related