C Arithmetic Operators

Beginner
6 min read
Updated: Nov 2026
1 example

What Is Arithmetic Operators?

Arithmetic operators perform math. / between two integers is integer division (the fraction is dropped), and % gives the remainder. % works only on integer types; use fmod from <math.h> for doubles.

Remember
a + b    a - b    a * b
a / b    /* int / int -> int, truncates toward zero */
a % b    /* remainder, sign follows a (C99) */
-a       /* unary minus */

Cheat Sheet

Keep these facts handy while you work with Arithmetic Operators in C.

TopicDetail
Division17 / 5 is 3; 17 / 5.0 is 3.4
Remainder17 % 5 is 2
Divide by zeroUndefined behavior for integers
Float remainderfmod(x, y) in <math.h>

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Relational Operators.

Example 1 — All five operators

Integer and floating-point division give different answers.

C
#include <stdio.h>

int main(void) {
    int a = 17, b = 5;

    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 / 5.0 = %.1f\n", a / 5.0);
    return 0;
}

How It Works

  1. a / b drops the fraction because both are int.
  2. %% in the format string prints a literal %.
  3. Using 5.0 makes the division floating point.

Edge Cases & Pitfalls

Check these before relying on Arithmetic Operators in real programs.

div0

Division by zero

x / 0 and x % 0 are undefined for integers. Check the divisor first.

neg

Negative remainders

-17 % 5 is -2 in C99 and later; the sign follows the left operand.

Key Takeaways

  • Integers: / truncates toward zero.
  • Remainder: % is integer-only.
  • Mix: one double operand gives a double result.

One line: Arithmetic operators perform math.

Frequently Asked Questions

Cast one operand: (double)a / b. Casting after the division is too late because the integer division has already run.
It returns the remainder after integer division, so 17 % 5 is 2. It is handy for even/odd checks and wrapping indexes.
Continue with "C Relational Operators" next. Compare values with == != < > <= >= and get 1 or 0. The C Operators hub lists every topic in order.

Next: Relational Operators

Compare values with == != < > <= >= and get 1 or 0.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful