Table of contents
1.
Introduction
2.
What are arithmetic operators in C?
2.1.
Example
2.2.
C
3.
Types of Arithmetic Operators in C
4.
Binary Arithmetic Operators in C
4.1.
Example of Binary Arithmetic Operator in C
4.2.
C
5.
Unary Arithmetic Operators in C
5.1.
Increment Operator in C
5.1.1.
1. Pre-Increment
5.1.2.
2. Post-Increment
5.2.
Decrement Operator in C
5.2.1.
1. Pre-Decrement
5.2.2.
2. Post-Decrement
5.3.
Example of Unary Arithmetic Operator in C
5.4.
C
6.
Frequently Asked Questions
6.1.
Name the list of arithmetic operators in C language?
6.2.
What is the use of the modulus operator in C?
6.3.
How does the division operator work with different operand types?
6.4.
What are arithmetic logical and relational operators in C?
6.5.
What is the difference between increment/decrement operators and addition/subtraction?
6.6.
Why is it called arithmetic?
7.
Conclusion
Last Updated: Dec 12, 2024
Easy

Arithmetic Operators in C

Author Rahul Singh
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Arithmetic operators are fundamental in any programming language, and C is no exception. These operators perform various mathematical operations, from basic addition and subtraction to more complex operations like modulus and exponentiation. The operators include addition (+), subtraction (-), multiplication (*), division (/), and modulo (%).

Arithmetic operators in c

What are arithmetic operators in C?

Arithmetic operators are symbols used to perform mathematical calculations. The main arithmetic operators in C are addition +, subtraction -, multiplication *, division /, and modulus %.

Example

  • C

C

#include <stdio.h>
int main() {
   int a = 10, b = 5;
   printf("Addition: %d\n", a + b);
   printf("Subtraction: %d\n", a - b);
   printf("Multiplication: %d\n", a * b);
   printf("Division: %d\n", a / b);
   printf("Modulus: %d\n", a % b);

   return 0;
}
You can also try this code with Online C Compiler
Run Code

 

Output

Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2
Modulus: 0


In the above code, each line performs an arithmetic operation on variables a and b using different arithmetic operators.

Types of Arithmetic Operators in C

There are two main types of arithmetic operators in C

  • Binary arithmetic operators
  • Unary arithmetic operators 

Binary Arithmetic Operators in C

OperatorDescriptionExample
+Additiona + b
-Subtractiona - b
*Multiplicationa * b
/Divisiona / b
%Modulus (Remainder)a % b

Example of Binary Arithmetic Operator in C

In this example, we will use two binary operators – “-” and “*” in C and print the result using printf().

  • C

C

#include <stdio.h>

int main() {
int res = 75 - 5*5;
printf("%d", res);

return 0;
}
You can also try this code with Online C Compiler
Run Code

 

Output

output

Unary Arithmetic Operators in C

OperatorDescriptionExample
+Unary Plus+a
-Unary Minus-a
++Incrementa++
--Decrementa--

Increment Operator in C

The unary increment operator("++") in C is used for incrementing the value of a variable by one. 

1. Pre-Increment

This is performed by using this operator before a variable, which increments the variable's value before it is used in an expression.

2. Post-Increment

This is performed by using this operator after a variable, which increments the variable's value after it is used in an expression.

Decrement Operator in C

The unary decrement operator("--") in C is used for decrementing the value of a variable by one. 

1. Pre-Decrement

This is performed by using this operator before a variable, which decrements the variable's value before it is used in an expression.

2. Post-Decrement

This is performed by using this operator after a variable, which decrements the variable's value after it is used in an expression.

Example of Unary Arithmetic Operator in C

In this example, we will use two unary operators – “++” and “--” in C and print the result using printf().

  • C

C

#include <stdio.h>

int main() {
int a = 48, b = 3;
int res = (a++) + (--b) ;
printf("%d", res);

return 0;
}
You can also try this code with Online C Compiler
Run Code

 

Output

output

Frequently Asked Questions

Name the list of arithmetic operators in C language?

  • ( + ) Addition Operator.
  • ( – ) Subtraction Operator.
  • ( * ) Multiplication Operator.
  • ( / ) Division Operator.
  • ( % ) Modulo Operator.
  • ( ++ ) Increment Operator.
  • ( — ) Decrement Operator.
  • ( + ) Unary Plus Operator.

What is the use of the modulus operator in C?

In C's arithmetic operators, the modulus operator calculates the remainder of integer division between two operands. It divides the numerator by the denominator to determine the result, effectively producing the remainder.

How does the division operator work with different operand types?

If both operands are integers, the result of the division operation will be an integer. If one or both operands are floating points, the result will be a floating-point number.

What are arithmetic logical and relational operators in C?

In C programming language, arithmetic operators perform mathematical operations (+, -, *, /, %). Logical operators work with boolean values (&&, ||, !) for logical expressions. Relational operators compare values (==, !=, <, >, <=, >=).

What is the difference between increment/decrement operators and addition/subtraction?

The Increment Operator adds 1 to the operand, while the Decrement Operator subtracts 1 from the operand. The Postfix decrement operator involves evaluating the expression with the variable's initial value before decreasing the variable itself.

Why is it called arithmetic?

Arithmetic, derived from the Greek word arithmos (meaning "number"), focuses on basic mathematical operations: addition, subtraction, multiplication, and division. It's foundational for numerical calculations and forms the basis for advanced mathematical concepts and problem-solving.

Conclusion

Arithmetic operators in C allow programmers to perform a variety of mathematical calculations, making them an indispensable part of the language. Understanding these operators and their specific behaviors is vital for writing efficient and effective C code. 

Recommended articles:

Live masterclass