Thuta Learning
BasicProgrammingbeginner

Operators

Relax. We'll talk through this in plain words — no textbook voice.

Operators are symbols used to calculate, compare, and check conditions between values. It's a lot like using a calculator, but in programming you also need to watch out for operator priority and how data types affect the result.

cpp
#include <iostream>
using namespace std;

int main() {
    int x = 10;
    int y = 3;

    cout << "Sum: " << x + y << endl;
    cout << "Remainder: " << x % y << endl;
    cout << "Is x greater? " << (x > y) << endl;

    x += 5;
    cout << "Updated x: " << x;
    return 0;
}

+ adds, % finds the remainder, > compares values, and += adds to the current value. (x > y) evaluates to true, so the console prints 1.

You should see
Sum: 13 Remainder: 1 Is x greater? 1 Updated x: 15

Info

/ between two integers can result in integer division. If you want a decimal result, make sure at least one of the values is a double.

Easy traps

  • A very common mistake is using = when you mean to compare. = assigns a value, while == checks for equality.
Operators | Thuta Learning