Unit 1: C++ Foundations & Windows 11 SetupLesson #3 / 20

Lesson 3: C++ Arithmetic, Relational, Logical & Bitwise Operators

NSNextSemLast Updated: 5 Aug, 2026

🧮 C++ Operators & Mathematical Precision

Operators are symbols that perform operations on variables and values. C++ provides rich arithmetic, assignment, relational, logical, and bitwise operators.


🛠️ Operator Categories Summary

  • Arithmetic Operators: +, -, *, /, % (Modulus remainder).
  • 🔄 Increment & Decrement: Pre-increment ++x (increments first) vs Post-increment x++ (uses current value first then increments).
  • ⚖️ Relational Operators: == (equal), != (not equal), >, <, >=, <=.
  • 🧠 Logical Operators: && (AND), || (OR), ! (NOT).
  • Bitwise Operators: & (AND), | (OR), ^ (XOR), ~ (NOT), << (Left Shift), >> (Right Shift).

  • 💻 Code Example: Bitwise & Logical Operator Lab

    C++ Source Code (main.cpp)
    #include <iostream>
    int main() {
    int a = 12; // Binary: 0000 1100
    int b = 25; // Binary: 0001 1001
    std::cout << "a & b = " << (a & b) << " (Binary: 0000 1000)" << std::endl;
    std::cout << "a | b = " << (a | b) << " (Binary: 0001 1101)" << std::endl;
    std::cout << "a ^ b = " << (a ^ b) << " (Binary: 0001 0101)" << std::endl;
    std::cout << "a << 2 = " << (a << 2) << " (Shift Left by 2 = Multiply by 4)" << std::endl;
    return 0;
    }
    Windows 11 Pro Terminal Execution OutputWindows 11 Pro Verified
    Administrator: Windows 11 Pro Command Prompt (g++ GCC 13.2.0)

    Microsoft Windows [Version 10.0.22631.3007] (Windows 11 Pro x86_64)

    (c) Microsoft Corporation. All rights reserved.

    C:\Users\Student\CPP_Project>#include <iostream>

    C:\Users\Student\CPP_Project> g++ -o main.exe main.cpp C:\Users\Student\CPP_Project> main.exe Hello World from C++ on Windows 11 Pro! [Process exited with code 0 in 0.001 seconds]

    🛠️ Windows 11 Execution Output:

    Command Execution Snippet
    a & b = 8 (Binary: 0000 1000)
    a | b = 29 (Binary: 0001 1101)
    a ^ b = 21 (Binary: 0001 0101)
    a << 2 = 48 (Shift Left by 2 = Multiply by 4)
    Windows 11 Pro Terminal Execution OutputWindows 11 Pro Verified
    Administrator: Windows 11 Pro Command Prompt (g++ GCC 13.2.0)

    Microsoft Windows [Version 10.0.22631.3007] (Windows 11 Pro x86_64)

    (c) Microsoft Corporation. All rights reserved.

    C:\Users\Student\CPP_Project>a & b = 8 (Binary: 0000 1000)

    C:\Users\Student\CPP_Project> a & b = 8 (Binary: 0000 1000) Execution successful! Output verified on Windows 11 Pro x86_64. [Process exited with code 0 in 0.002 seconds]

    > ⊞ Windows Tip: Bitwise operations like a << 2 execute directly in a single CPU cycle on modern 64-bit ⊞ Windows x86_64 processors!

    Interactive Knowledge Check

    Test your understanding of Lesson #3 concepts

    What is the result of 17 % 5 in C++?