1.
Introduction
2.
What are arithmetic operators in C?
2.1.
Example
2.2.
C
2.3.
Output
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.
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?
7.
Conclusion
Last Updated: Mar 27, 2024
Easy

Arithmetic Operators in C

Rahul Singh
0 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

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 (%).

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

• 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;}``

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.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

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

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;}``

Output:

Unary Arithmetic Operators in C

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;}``

Output:

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.

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:

We hope this blog helped you to understand the concept of the Arithmetic Operators in C. You can refer to our guided paths on the Coding Ninjas Studio platform. You can check our course to learn more about DSADBMSCompetitive ProgrammingPythonJavaJavaScript, etc.

To practice and improve yourself in the interview, you can also check out Top 100 SQL problemsInterview experienceCoding interview questions, and the Ultimate guide path for interviews

Happy Learning!!

Live masterclass