C Arithmetic Operators

In this lesson, you will learn about Arithmetic Operations in C, and their usages, along with examples to better understand the topic.

What are Arithmetic Operators in C?

Like in general mathematics, operators are utilized for performing operations on variables. The following C arithmetic operators are given below and used for numeric values to perform common arithmetical operations.

Arithmetic Operators Symbol Arithmetic Operators’ Names Example
+ Addition a + b
Substraction a – b
* Multiplication a * b
/ Division a / b
% Modulus a % b
** Exponentiation a ** b
++ Increment a++
Decrement a–

Example of Arithmetic operations in C

// Example of constant statement
#include <stdio.h>

int a, b, c;
int main() {
  printf("C Arithmetic Operators Example\n");
  printf("----------------------------------------\n");
  a = 25;
  b = 20;
  printf("%d = 25", a);
  printf("\n");
  printf("%d = 20", b);
  printf("\n");
  c = +a;
  printf("Identity Operator->+a =%d ", c);
  printf("\n");
  c = -a;
  printf("Negation Operator->-a =%d ", c);
  printf("\n");
  c = a + b;
  printf("Add Operator-> a + b = %d", c);
  printf("\n");
  c = a - b;
  printf("Substract Operator -> a - b = %d", c);
  printf("\n");
  c = a * b;
  printf("Multiply Operator -> a * b = %d", c);
  printf("\n");
  c = a / b;
  printf("Divide Operator -> a / b = %d", c);
  c = a % b;
  printf("\n");
  printf("Modulus Operator -> a %% b = %d", c);
  c = a % -b;
  printf("\n");
  printf("Modulus Operator -> a %% -b = %d", c);
  c = -a % b;
  printf("\n");
  printf("Modulus Operator -> -a %% b = %d", c);
  c = -a % -b;
  printf("\n");
  printf("Modulus Operator -> -a %% -b = %d", c);
  c = a++;
  printf("\n");
  printf("Increment Operation -> a++ = %d", c);
  printf("\n");
  c = a--;
  printf("Decrement Operation -> a -- = %d", c);
  printf("\n");
  return 0;
}

Output

C Arithmetic Operators Example
----------------------------------------
25 = 25
20 = 20
Identity Operator->+a =25
Negation Operator->-a =-25
Add Operator-> a + b = 45
Substract Operator -> a - b = 5
Multiply Operator -> a * b = 500
Divide Operator -> a / b = 1
Modulus Operator -> a % b = 5
Modulus Operator -> a % -b = 5
Modulus Operator -> -a % b = -5
Modulus Operator -> -a % -b = -5
Increment Operation -> a++ = 25
Decrement Operation -> a -- = 26

In the next lesson, you will learn Comparison Operations and the usages in the C programming language.