C & C++ fundamentals / 05

Operators

Arithmetic, assignment, comparison, increment, decrement, and logical operators in C and C++.

On this page

You can perform calculations on values read by a C/C++ program. In addition to ordinary arithmetic, libraries provide functions such as sin, cos, and tan. Let's first look at the operators used most often in basic code.

Assignment and arithmetic

In mathematics, a = b + c expresses equality. In C/C++, it means calculate b + c and assign the result to a. For example, a = 1 + 2 stores 3 in a.

If a contains 3, printf("%d", a); replaces the %d placeholder with that value and prints 3. To compare whether a and b are equal, use a == b instead of assignment.

+  Addition        a = b + c   Assign the sum to a
-  Subtraction     a = b - c   Assign the difference to a
*  Multiplication  a = b * c   Assign the product to a
/  Division        a = b / c   Assign the quotient to a
%  Remainder       a = b % c   Assign the remainder to a

Integer division discards the fractional part. The % operator works with integer operands; it does not calculate a floating-point remainder. Also remember that % has a different role inside a formatted input/output string.

Compound assignment

a += b   Assign a + b to a
a -= b   Assign a - b to a
a *= b   Assign a * b to a
a /= b   Assign a / b to a
a %= b   Assign a % b to a

Comparisons

a == b   a is equal to b
a = b    Assign b to a (assignment, not comparison)
a != b   a is not equal to b
a <= b   a is less than or equal to b
a >= b   a is greater than or equal to b
a < b    a is less than b
a > b    a is greater than b

Prefix and postfix operators

a++   Use the previous value, then increment a by 1
++a   Increment a by 1, then use the new value
a--   Use the previous value, then decrement a by 1
--a   Decrement a by 1, then use the new value

Logical operators

a && b   Both a and b must be true (AND)
a || b   At least one of a or b must be true (OR)
!a       a is not true (NOT)
!b       b is not true (NOT)

An expression such as !a reverses its truth value: true becomes false, and false becomes true. These operators will appear more and more often as the lessons progress, so make sure you are comfortable with them.

Translation note: the operator reference blocks have been translated into English. The original compound-assignment table repeated += beside multiplication and division; those labels are corrected here.

Moved here from Tistory

I migrated this post from my Korean Tistory blog, I am Jason Lee, to this website and translated it into English. My writing and projects now live together in one place.

The original publication date, code examples, and screenshots are preserved. Editorial notes clarify known issues in the original material.

Original post on Tistory English edition · Aug 30, 2026
← Back to all articles