Arithmetic Operations in C
The arithmetic operators are used to perform arithmetic/mathematical operations on operands. There are 9 arithmetic operators in C language:
S. No. | Symbol | Operator | Description | Syntax |
---|---|---|---|---|
1 | + | Plus | Adds two numeric values. | a + b |
2 | – | Minus | Subtracts right operand from left operand. | a – b |
3 | * | Multiply | Multiply two numeric values. | a * b |
4 | / | Divide | Divide two numeric values. | a / b |
5 | % | Modulus | Returns the remainder after diving the left operand with the right operand. | a % b |
6 | + | Unary Plus | Used to specify the positive values. | +a |
7 | – | Unary Minus | Flips the sign of the value. | -a |
8 | ++ | Increment | Increases the value of the operand by 1. | a++ |
9 | — | Decrement | Decreases the value of the operand by 1. | a– |
Example of C Arithmetic Operators
// C program to illustrate the arithmatic operators
#include <stdio.h>
int main()
{
int a = 25, b = 5;
// using operators and printing results
printf("a + b = %d\n", a + b);
printf("a - b = %d\n", a - b);
printf("a * b = %d\n", a * b);
printf("a / b = %d\n", a / b);
printf("a % b = %d\n", a % b);
printf("+a = %d\n", +a);
printf("-a = %d\n", -a);
printf("a++ = %d\n", a++);
printf("a-- = %d\n", a--);
return 0;
}
Output
a + b = 30 a - b = 20 a * b = 125 a / b = 5 a % b = 0 +a = 25 -a = -25 a++ = 25 a-- = 26
Operators in C
In C language, operators are symbols that represent operations to be performed on one or more operands. They are the basic components of the C programming. In this article, we will learn about all the built-in operators in C with examples.