If I do:
int i=3, j=10;
float f;
f=(i+j)/2;
so f won't get value 6.5 but 6.
But,
f=(i+(float)j)/10;//edited
would be f=6.5.
What is the place where this temporary values are stored and why do we need to type-cast?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
is incorrect; the type in a cast comes before its operand:
Anyway. When evaluating an arithmetic operator, if one operand is of a floating point type and the other is of an integer type, then the integer operand is converted to the floating point type and floating arithmetic is performed.
This is part of what are called the usual arithmetic conversions (you can find out more about those by searching Google, though MSDN has a simple explanation of what they are).
Where the temporary value is stored depends on the compiler and the computer. It’s likely to be stored in a register since you’re going to use it immediately, but it could be stored on the stack or somewhere else.