🧮 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
💻 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!