Tutorials

C Operator


C Arithmetic Operator


In C, we have five arithmetic operators that are frequently used and they are given in the set {+, -, *, /, %}

 

Arithmetic operators can be used for arithmetic calculations. 

 

The result will be in real number, when the operands are a real numbers.

The modulus operation gives the remainder as result. Therefore, it requires an integer value; otherwise you will get an error.

 

Please see the chart given below to understand the basic functionality of each of the arithmetic operators.

 

Operators

Meaning

Example

Output

+

Addition or Unary plus

7+2

9

-

Subtraction or Unary minus

7-2

5

*

Multiplication

7*2

14

/

Division

7/2

7.0/2

3

3.5

%

Modulus

7%2

1

Algebraic Expression to C Expression

  • a+bc    ⇒     a+b*c
  • a^2 + b^2 ⇒ a*a+b*b

Precedence of Arithmetic Operators

The precedence of arithmetic operators in C is:

  1. Parentheses ( )
  2. Unary operators (+, -)
  3. Exponent( )
  4. Multiplication (*), division (/), modulus (%)
  5. Addition (+), Subtraction (-)

The expression evaluated from left to right. The operators that appear first will be evaluated first, in the case of equal priority.

 

 



Please Share this page
Views : 59
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!