Arithmetic Operators in C Programming

In C programming, arithmetic operators are fundamental tools used to perform basic mathematical operations on numeric values

Arithmetic Operators in C Programming

These Operators allow you to carry out basic operations such as:

  1. Addition(+)
  2. subtraction(-)
  3. Multiplication(*)
  4. Division(/)
  5. Modulus(%) 

Rules for Arithmetic operators:

  •  Precedence rule:If we have more than one operator then  the question arises that which will be evalute first. 

for example:     

int z= 3+3*4/5-2
       = 3+(3*4)/5-2// mul and division operators have higher precedence than add and sub and after that follow associative rule
       = 3+12/5-2
       = (3+2)-2// for arithmetic operators associativity is from left to right.
       =5-2
       =3

Precedence:      

 

       ()

    *, / , %

      +, -

 

 

  • Integer /Integer is always integer like 5/2 is 2 and not 2.5. we have to ignore float value and the output should be a floor value 
  • Associative rule: If more than one Operator is having same precedence in an expression then we have to follow associative rule.

   

Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings

               

which one we should follow first one or second one. that can be determine by associative rule.

"For All arithematic operators associativity is from left to right"

therefore, -7 is correct answer.

practice Questions:

  1.  If int takes 2 bytes then, int x=300*300/300; , what is the value of x?
  2. int x=3/3/3/3; what is the value of x?
  3. evaluate the expression 3+3*4*3/6/4*3-2 and give final value.
  4. evaluate the expression 13/4*3%5 and give the final value.

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow