← Back to C Course | Chapter 3: Operators | Lesson 2 of 9

C Arithmetic Operators

Addition (+) and Subtraction (-)

The + and - operators perform ordinary addition and subtraction on numeric values, working the same way for int, float, or double operands, following standard mathematical rules of precedence within larger expressions.

Example: Addition (+) and Subtraction (-)

c
#include <stdio.h>
int main() {
	int a = 10, b = 3;
	printf("%d %d", a + b, a - b);
	return 0;
}

Multiplication () and Division (/)

The * operator multiplies two values, and / divides them -- but dividing two integers in C performs integer division, silently discarding any fractional remainder, which surprises many beginners expecting a decimal result.

Example: Multiplication () and Division (/)

c
#include <stdio.h>
int main() {
	int a = 7, b = 2;
	printf("%d %d", a * b, a / b);
	return 0;
}

Modulo Operator (%)

% returns only the remainder left over after integer division, making it the standard way to test whether a number is even or odd (checking n % 2 == 0) or to wrap a counter back to zero after reaching a limit.

Example: Modulo Operator (%)

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

Increment Operator (++)

++ increases a variable's value by exactly 1. Written before the variable (++x) it applies the increase before the variable is used in the surrounding expression; written after (x++) it applies the increase afterward.

Example: Increment Operator (++)

c
#include <stdio.h>
int main() {
	int x = 5;
	printf("%d %d", ++x, x++);
	return 0;
}

Decrement Operator (--)

-- decreases a variable's value by exactly 1, following the same prefix/postfix timing rules as ++ -- prefix decrements before the value is used in an expression, postfix decrements immediately after.

Example: Decrement Operator (--)

c
#include <stdio.h>
int main() {
	int x = 5;
	printf("%d %d", --x, x--);
	return 0;
}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.