What is Operators?
An operator is a symbol that operates on a value or a variable. For example: + is an operator to perform addition.
Types of Operators:
- Arithmetic Operators
- Increment and Decrement Operators
- Assignment Operators
- Relational/ Comparison Operators
- Logical Operators
- Bitwise Operators
- Comma Operator
- The sizeof operator
C Arithmetic Operators
An arithmetic operator performs mathematical operations such as addition, subtraction, multiplication, division etc on numerical values (constants and variables).
Operator | Meaning of Operator |
---|---|
+ | addition or unary plus |
– | subtraction or unary minus |
* | multiplication |
/ | division |
% | remainder after division (modulo division) |
Example 1: Arithmetic Operators
#include <stdio.h> void main() { int a = 9,b = 4, c; // Working of arithmetic operators c = a+b; printf("a+b = %d \n",c); c = a-b; printf("a-b = %d \n",c); c = a*b; printf("a*b = %d \n",c); c = a/b; printf("a/b = %d \n",c); c = a%b; printf("Remainder when a divided by b = %d \n",c); }
Output
a+b = 13 a-b = 5 a*b = 36 a/b = 2 Remainder when a divided by b=1
Suppose a = 5.0
, b = 2.0
, c = 5
and d = 2
. Then in C programming,
// Either one of the operands is a floating-point number a/b = 2.5 a/d = 2.5 c/b = 2.5 // Both operands are integers c/d = 2