Operators in C

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:

  1. Arithmetic Operators
  2. Increment and Decrement Operators
  3. Assignment Operators
  4. Relational/ Comparison Operators
  5. Logical Operators
  6. Bitwise Operators
  7. Comma Operator
  8. 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).

OperatorMeaning 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.0b = 2.0c = 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

Leave a Comment