### in what type intermediate result of an expression is stored

i am having a doubt and i would appreciate the help.
my doubt is :- in what data type the intermediate result of an expression is stored?
like for expression 2+3*1/2 , i think the intermediate result for 1/2 is stored in the form 0.5
but for expression 2+3*1/100 , i think the intermediate result for 1/100 is stored in the form 0.01
so i am not sure if the compiler use dynamic type ie, changes with need. or it always stores in high precision like:- for 1/2 its 0.5000 and for 1/100 also 0.0100 or something like that.

and i would also appreciate some extra knowledge on this topic other than my doubt...
Last edited on
The compiler uses the Usual arithmetic conversions.
 The purpose is to determine a common real type for the operands and result.
(the C Standard)

In your example of expression 1 / 2 both operands have type int. So the common type for the operands and the result will be int. The value of the expression is 0.

EDIT: but if to consider the whole expression 2+3*1/2 then it result will be equal to 3.
Last edited on
See: http://msdn.microsoft.com/en-us/library/09ka8bxx(v=vs.110).aspx

Note: "Integral promotions are performed on the operands as follows:" is not entirely accurate.

It should have read: "integral promotions are first performed on both operands. After that, conversions as follows are applied:"
Last edited on
Everything stored or manipulated in a computer is in binary format.
A calculation is performed in accordance with the rules of precedence, associativity, and integer type promotion (converting an integer type (say short) of lower value to an integer type of higher value (say long).
Narrowing - e.g. attempting to fit a long int into a short int or a short int into a char int is generally not allowed.
for example:
The * operator has a higher precedence than the + operator
Where precedence is identical, L to R or R to L associativity rules apply.
In your int examples precedence requires 3 to be multiplied by 1 then divided by 2 and this result added to 2 with a result of 3 (3*1=3 /2=1 +2 =3)
Remember in integer arithmetic remainders from division are discarded and
if the numerator is smaller than the denominator the result will always be 0.
Thanks for all the help.
Topic archived. No new replies allowed.