Table of Contents
What Are Arithmetic Operators?
Arithmetic operators are symbols that perform operations on numeric values or variables. They are mainly used with data types like int, float, and double.- Basic Calculations: Arithmetic operators help in performing essential mathematical operations within programs.
- Numeric Support: These operators work with different numeric data types such as integers and floating-point values.
- Wide Usage: They are used in almost every program, from simple logic to complex computations.
Types of Arithmetic Operators in C
Here are the different types of arithmetic operators in C:
Addition (+)
The addition operator is used to add two values and return their sum.- Sum Operation: The addition operator combines two values to produce a total.
- Flexible Usage: It works with both integer and floating-point values.
- Common Usage: This operator is widely used in most programming scenarios.
// C program to show addition operator
#include stdio.h
// Main function
int main()
{
int a = 10, b = 5;
int result = a + b;
printf("Sum = %d", result);
return 0;
}
Output:
Sum = 15
Subtraction (-)
The subtraction operator is used to find the difference between two values.
- Difference Result: The subtraction operator calculates the difference between two values.
- Order Matters: Changing the order of operands can change the result.
- Negative Values: The result can be negative if the second value is larger.
// C program to show subtraction operator
#include stdio.h
// Main function
int main()
{
int a = 10, b = 5;
int result = a - b;
printf("Difference = %d", result);
return 0;
}
Output:
Difference = 5
Multiplication (*)
The multiplication operator is used to multiply two values.- Product Result: The multiplication operator produces the product of two values.
- All Types: It works with all numeric data types efficiently.
- Formula Usage: It is commonly used in mathematical formulas and calculations.
// C program to show multiplication operator
#include stdio.h
// Main function
int main()
{
int a = 4, b = 5;
int result = a * b;
printf("Product = %d", result);
return 0;
}
Output:
Product = 20
Division (/)
The division operator divides one value by another.- Quotient Result: The division operator returns the result of dividing two values.
- Integer Behavior: Integer division removes the decimal part of the result.
- Float Accuracy: Using float or double gives a more precise result.
- Zero Restriction: Division by zero is not allowed and causes errors.
// C program to show integer division
#include stdio.h
// Main function
int main()
{
int a = 10, b = 3;
int result = a / b;
printf("Result = %d", result);
return 0;
}
Output:
Example 2: Floating-Point DivisionResult = 3
// C program to show floating-point
// division
#include stdio.h
// Main function
int main()
{
float a = 10, b = 3;
float result = a / b;
printf("Result = %.2f", result);
return 0;
}
Output:
Result = 3.33
Modulus (%)
The modulus operator returns the remainder after division.- Remainder Value: The modulus operator gives the remainder of a division.
- Integer Only: It works only with integer values.
- Logical Use: It is useful for conditions like checking even or odd numbers.
// C program to show modulus operator
#include stdio.h
// Main function
int main()
{
int a = 10, b = 3;
int result = a % b;
printf("Remainder = %d", result);
return 0;
}
Output:
Remainder = 1
Operator Precedence and Associativity
Operator precedence defines the order in which operations are performed.
- Higher Priority: Multiplication, division, and modulus are evaluated first.
- Lower Priority: Addition and subtraction are evaluated afterward.
- Left Association: Operators of the same level are evaluated from left to right.
- Parentheses Control: Parentheses can change the default order of execution.

// C program to show operator
// precedence and associativity
#include stdio.h
// Main function
int main()
{
int result = 10 + 5 * 2 - 8 / 4;
printf("Result = %d", result);
return 0;
}
Output:
Result = 18
Increment and Decrement Operators
These operators increase or decrease a value by one.- Increment Use: The increment operator increases the value by one.
- Decrement Use: The decrement operator decreases the value by one.
- Pre Increment: The value is updated before it is used.
- Post Increment: The value is used before it is updated.

Example:
#include stdio.h
int main() {
int a = 5;
printf("Pre-increment = %d\n", ++a);
printf("Post-increment = %d\n", a++);
printf("Final value = %d", a);
return 0;
}
Output:
Pre-increment = 6
Post-increment = 6
Final value = 7
Common Mistakes to Avoid
- Wrong Division: Using integer division when a decimal result is expected can lead to incorrect output.
- Zero Division: Dividing by zero causes runtime errors in programs.
- Ignored Precedence: Not considering operator precedence can produce unexpected results.
- Invalid Modulus: Using modulus with floating-point values is not allowed.
Conclusion
Arithmetic operators in C are simple but extremely powerful. They form the base of calculations and logic in programming. Once you understand how each operator behaves, especially division and precedence, your programs become more reliable.The real improvement comes when you start using them in real problems. Practice small examples, experiment with expressions, and you’ll see how quickly everything starts to make sense.
Frequently Asked Questions
1. What is the difference between / and % in C?2. Why does integer division remove decimals?The division operator returns the quotient, while the modulus operator returns the remainder.
3. Can arithmetic operators be used with float values?Because both operands are integers, C discards the fractional part automatically.
4. What is operator precedence in C?Yes, all arithmetic operators except modulus (%) work with float values.
5. What is the difference between a++ and ++a?It defines the order in which operations are performed in an expression.
a++ uses the value first and then increments it, while ++a increments first and then uses it.
0 Comments