Arithmetic Operators in C – Complete Guide with Examples

Arithmetic operators in C perform mathematical computations on integer and floating-point values. C provides addition (+), subtraction (-), multiplication (*), division (/), modulo (%), increment (++), and decrement (--). Understanding how integer division truncates and how pre- versus post-increment differ are among the most common sources of bugs for beginners.

C Program for Arithmetic Operators

/* Arithmetic operators in C
 * Compile: gcc -ansi -Wall -Wextra arith.c -o arith */
#include <stdio.h>

int main(void)
{
    int a = 17, b = 5;
    int q, r;
    double x = 17.0, y = 5.0;

    printf("a = %d,  b = %d\n\n", a, b);

    /* Basic operators */
    printf("Addition:       a + b  = %d\n", a + b);
    printf("Subtraction:    a - b  = %d\n", a - b);
    printf("Multiplication: a * b  = %d\n", a * b);

    /* Integer division -- truncates toward zero */
    q = a / b;
    r = a % b;
    printf("Division:       a / b  = %d  (integer, truncated)\n", q);
    printf("Modulo:         a %% b  = %d  (remainder)\n", r);
    printf("Verify:         %d * %d + %d = %d\n\n", q, b, r, q * b + r);

    /* Float division */
    printf("Float div:      %.1f / %.1f = %.4f\n\n", x, y, x / y);

    /* Increment and decrement */
    printf("Pre-increment:  ++a = %d\n", ++a);
    printf("Post-increment: b++ = %d\n", b++);
    printf("After b++:      b   = %d\n", b);
    printf("Pre-decrement:  --a = %d\n", --a);

    return 0;
}

How to Compile and Run

gcc -ansi -Wall -Wextra arith.c -o arith
./arith

Sample Output

a = 17,  b = 5

Addition:       a + b  = 22
Subtraction:    a - b  = 12
Multiplication: a * b  = 85
Division:       a / b  = 3  (integer, truncated)
Modulo:         a % b  = 2  (remainder)
Verify:         3 * 5 + 2 = 17

Float div:      17.0 / 5.0 = 3.4000

Pre-increment:  ++a = 18
Post-increment: b++ = 5
After b++:      b   = 6
Pre-decrement:  --a = 17

Operator Reference Table

Operator Name Example Result
+ Addition 17 + 5 22
- Subtraction 17 – 5 12
* Multiplication 17 * 5 85
/ Division (int) 17 / 5 3 (truncated)
% Modulo (remainder) 17 % 5 2
++ Increment a++ or ++a adds 1 to a
-- Decrement a– or –a subtracts 1

Code Explanation

  • Integer division truncates17 / 5 gives 3, not 3.4. The fractional part is discarded entirely. To get the decimal result, at least one operand must be a double: 17.0 / 5 gives 3.4.
  • Modulo operator % — gives the remainder after integer division. 17 % 5 = 2 because 17 = 3×5 + 2. The relationship a == (a/b)*b + (a%b) always holds.
  • Pre-increment ++a — increments a first, then uses the new value in the expression. printf("%d", ++a) where a=17 prints 18.
  • Post-increment b++ — uses the current value in the expression, then increments. printf("%d", b++) where b=5 prints 5, and only after does b become 6.
  • %% in printf — to print a literal % in a printf format string, write %%. A single % would start a format specifier and cause undefined behaviour.

What This Program Teaches

  • Integer vs floating-point division — the type of the operands determines whether division truncates. This is one of the most common bugs in C programs.
  • Modulo and the division identity — understanding that a == (a/b)*b + (a%b) helps when extracting digits, checking divisibility, or implementing cyclic counters.
  • Pre vs post increment — the order of increment vs use matters in expressions. Keeping increment statements on their own line avoids subtle bugs.
  • Operator precedence* and / bind more tightly than + and -. Use parentheses when in doubt: (a + b) * c is unambiguous.

Related Programs

Recommended book:
The C Programming Language — Kernighan & Ritchie (India) |
(US)
 | 
C Programming: A Modern Approach — K.N. King (India) |
(US)

Practice what you learned: C Aptitude Questions — or try our C Programming Quiz App on Android.