Operators and Comparisons
LockedLesson 2 of 25 · Syntax · Easy
Finish these first:Variables and Primitive Types →Or pass the tests below to unlock it now.
The big idea
Operators let C++ perform math and compare values. Write the math on the right side of =, and C++ saves the result into the variable on the left: Remember to put the type (int) before the variable name and finish the line with a semicolon ;.
Think of it like this: Think of C++ operators (`+`, `-`, `*`, `/`) like calculator buttons that work out the right side first and store the answer in your variable.
Read the lesson
Operators let C++ perform math and compare values.
Write the math on the right side of =, and C++ saves the result into the variable on the left:
int apples = 3 + 5; // 8
int change = 10 - 4; // 6
int area = 3 * 4; // 12
int half = 10 / 2; // 5
Remember to put the type (int) before the variable name and finish the line with a semicolon ;.
Quick check
What value is stored in `sum` after running `int sum = 3 + 5;`?
Your challenge
Inside main(), create an int variable named total that adds 4 and 6 (type int total = 4 + 6;).
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to python.operators (90% overlap). Arithmetic and boolean operators behave identically; watch === in JS and integer division in C++/Go/Rust/Java.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Operators and Comparisons.