C Program to understand the Arithmetic Operators And their Precedence.
PROGRAM:

 
Output: (using GNU GCC Compiler with Code Blocks IDE)
Addition Result: 30
Subtraction Result is: 20
Multiplication Result is : 125
Division Result is: 5
Division Result Remainder is: 0
The Result of (a+b*c/d): 37
The Result of (a+b-c*d): -10
The Result of (++a + b++ /d): 27
EXPLANATION:
Every time the variable result is overwritten with a new value and printing
 
Precedence1:  a+b*c/d;
              i)   c*d = 50
             ii) (c*d)/d i.e.,50/4=12.5
(here float value is not considered because result is declared as int)
            iii) 12 is added to a (25+12=37)
precedence2: a+b-c/d;
             i) c/d is evaluated
            ii) b-(c/d) evaluated
           iii) a+(b-(c/d)) evaluated
precedence3:  ++a+b++/d;
              i)a value incremented
             ii)b value incremented
            iii)b++/d evaluated
            iv)++a + (b++/d) is evaluated

Leave a Reply

Your email address will not be published. Required fields are marked *