C++ Arithmetic Operators

➕➖✖️➗ C++ Arithmetic Operators

Arithmetic Operators ka use mathematical calculations ke liye hota hai jaise addition, subtraction, multiplication, division, etc.


🔹 1. List of Arithmetic Operators

Operator Name Example
+ Addition a + b
- Subtraction a - b
* Multiplication a * b
/ Division a / b
% Modulus (remainder) a % b

🔹 2. Addition (+)

int a = 10, b = 5;
cout << a + b;

Output:

15

🔹 3. Subtraction (-)

cout << a - b;

Output:

5

🔹 4. Multiplication (*)

cout << a * b;

Output:

50

🔹 5. Division (/)

Integer Division

int x = 10, y = 3;
cout << x / y;

Output:

3

Floating Division

cout << (float)x / y;

Output:

3.33333

🔹 6. Modulus (%)

cout << 10 % 3;

Output:

1

⚠️ % sirf integer types ke liye hota hai.


🔹 7. Arithmetic with Variables

int a = 20, b = 4;
int sum = a + b;
int diff = a - b;
int prod = a * b;
int div = a / b;

🔹 8. Combined Example

#include <iostream>
using namespace std;
int main() {
int a = 15, b = 4;

cout << “Add = “ << a + b << “\n”;
cout << “Sub = “ << a – b << “\n”;
cout << “Mul = “ << a * b << “\n”;
cout << “Div = “ << a / b << “\n”;
cout << “Mod = “ << a % b;

return 0;
}


❌ Common Mistakes

cout << 5 / 2; // gives 2, not 2.5

✔ Fix:

cout << 5.0 / 2;

📌 Summary

  • Arithmetic operators math operations ke liye

  • / integer division me decimal drop hota hai

  • % sirf integers ke liye

  • Type casting se accurate result milta hai

You may also like...