Arithmetic operators in C are used to perform mathematical operations such as addition, subtraction, multiplication, division, and modulus on numeric data types (e.g., int, float, double).
List of Arithmetic Operators:
| Operator | Name | Description | Example |
|---|---|---|---|
+ | Addition | Adds two operands | a + b |
- | Subtraction | Subtracts second operand from the first | a - b |
* | Multiplication | Multiplies two operands | a * b |
/ | Division | Divides first operand by second | a / b |
% | Modulus | Returns remainder of division (integers) | a % b |
Note: The % operator only works with integers, not float or double.
Example Program Using Arithmetic Operators:
#include <stdio.h>
int main() {
int a = 20, b = 7;
printf("Addition: %d + %d = %d\n", a, b, a + b);
printf("Subtraction: %d - %d = %d\n", a, b, a - b);
printf("Multiplication: %d * %d = %d\n", a, b, a * b);
printf("Division: %d / %d = %d\n", a, b, a / b); // Integer division
printf("Modulus: %d %% %d = %d\n", a, b, a % b); // Note: %% to print %
return 0;
}Output:
Addition: 20 + 7 = 27
Subtraction: 20 - 7 = 13
Multiplication: 20 * 7 = 140
Division: 20 / 7 = 2
Modulus: 20 % 7 = 6
Discussion 0