Skip to main content
Course/Module 1/Topic 3 of 4Beginner

Operators & Expressions

Learn arithmetic, comparison, and logical operators in C++.

20 minBy Priygop TeamLast updated: Feb 2026

C++ Operators

C++ inherits all operators from C and adds more. Arithmetic operators perform math. Comparison operators return bool (true/false). Logical operators combine boolean conditions. C++ also has the scope resolution operator (::) and other OOP-specific operators you'll learn later.

Common Operators

  • + - * / % — Arithmetic
  • ++ -- — Increment / Decrement
  • == != > < >= <= — Comparison (return bool)
  • && || ! — Logical AND, OR, NOT
  • += -= *= /= — Compound assignment
  • << — Stream insertion (output with cout)
  • >> — Stream extraction (input with cin)

Operators Example

Example
#include <iostream>
using namespace std;

int main() {
    int a = 10, b = 3;

    cout << "a + b = " << (a + b) << endl;  // 13
    cout << "a - b = " << (a - b) << endl;  // 7
    cout << "a * b = " << (a * b) << endl;  // 30
    cout << "a / b = " << (a / b) << endl;  // 3
    cout << "a % b = " << (a % b) << endl;  // 1

    // Comparison
    cout << "a > b: " << (a > b) << endl;   // 1 (true)
    cout << "a == b: " << (a == b) << endl; // 0 (false)

    // Logical
    bool x = true, y = false;
    cout << "x && y: " << (x && y) << endl; // 0
    cout << "x || y: " << (x || y) << endl; // 1

    // Increment
    int count = 5;
    count++;
    cout << "count++: " << count << endl; // 6

    return 0;
}

Try It Yourself: Calculator

Try It Yourself: CalculatorC++
C++ Editor
✓ ValidTab = 2 spaces
C++|20 lines|614 chars|✓ Valid syntax
UTF-8

Quick Quiz

Chat on WhatsApp
Priygop - Leading Professional Development Platform | Expert Courses & Interview Prep