0Pricing
C Academy · Lesson

Arithmetic Operators

+, -, *, /, %.

Arithmetic Operators is a free C Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Arithmetic in C

C gives you the everyday math operators you already know. They let you turn variables into expressions that compute new values.

  • + addition
  • - subtraction
  • * multiplication
  • / division
  • % modulo (remainder)
#include <stdio.h>
int main(void) {
    int a = 7, b = 3;
    printf("a + b = %d\n", a + b);
    printf("a - b = %d\n", a - b);
    return 0;
}

Multiplication

The * operator multiplies two values. The result type follows the operands, so two int values produce an int.

#include <stdio.h>
int main(void) {
    int width = 4, height = 5;
    int area = width * height;
    printf("Area = %d\n", area);
    return 0;
}

Integer Division

When both operands are integers, / performs integer division and discards the fractional part.

So 7 / 2 is 3, not 3.5.

#include <stdio.h>
int main(void) {
    int x = 7, y = 2;
    printf("7 / 2 = %d\n", x / y);
    return 0;
}

Floating Point Division

To keep the fractional part, make at least one operand a floating-point value. Then / performs real division.

#include <stdio.h>
int main(void) {
    double x = 7.0, y = 2.0;
    printf("7.0 / 2.0 = %.2f\n", x / y);
    return 0;
}

The Modulo Operator

The % operator gives the remainder of integer division. It only works with integer operands.

7 % 3 is 1 because 7 = 2*3 + 1.

#include <stdio.h>
int main(void) {
    printf("7 %% 3 = %d\n", 7 % 3);
    printf("10 %% 5 = %d\n", 10 % 5);
    return 0;
}

Modulo Use Case: Even or Odd

A common trick: a number is even when n % 2 == 0, and odd otherwise.

#include <stdio.h>
int main(void) {
    int n = 9;
    if (n % 2 == 0)
        printf("%d is even\n", n);
    else
        printf("%d is odd\n", n);
    return 0;
}

Unary Minus

The - operator also works as a unary operator to negate a value.

#include <stdio.h>
int main(void) {
    int temp = 5;
    printf("Negated: %d\n", -temp);
    return 0;
}

Mixing int and double

When you mix types, C promotes the int to double before computing. This is called type promotion.

#include <stdio.h>
int main(void) {
    int a = 5;
    double b = 2.0;
    printf("Result = %.2f\n", a / b);
    return 0;
}

Division by Zero

Integer division or modulo by zero is undefined behavior in C and usually crashes the program. Always guard against a zero divisor.

#include <stdio.h>
int main(void) {
    int n = 10, d = 0;
    if (d != 0)
        printf("%d\n", n / d);
    else
        printf("Cannot divide by zero\n");
    return 0;
}

Combining Operators

You can chain operators to build larger expressions. C evaluates them according to precedence rules you will study soon.

#include <stdio.h>
int main(void) {
    int total = 2 + 3 * 4 - 1;
    printf("total = %d\n", total);
    return 0;
}

A Small Calculator

Putting it together: read two values into variables and print several arithmetic results at once.

#include <stdio.h>
int main(void) {
    int a = 12, b = 5;
    printf("Sum: %d\n", a + b);
    printf("Diff: %d\n", a - b);
    printf("Quot: %d\n", a / b);
    printf("Rem: %d\n", a % b);
    return 0;
}

Quick Check

Test your understanding of arithmetic operators.

Recap: Arithmetic Operators

You learned the five arithmetic operators in C.

  • + - * behave as expected
  • / truncates for integers but gives real results with floats
  • % gives the remainder and is integer-only
  • Mixing types promotes to the wider type
  • Never divide by zero

Frequently asked questions

Is the “Arithmetic Operators” lesson free?

Yes — the full text of “Arithmetic Operators” is free to read here on the web, and the C Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO.

What will I learn in “Arithmetic Operators”?

+, -, *, /, %. You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start C Academy?

No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Arithmetic Operators” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this C Academy lesson?

Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Arithmetic Operators
  2. Relational and Logical
  3. Assignment and Increment
  4. Operator Precedence
← Back to C Academy