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...
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.
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.