C++ Arithmetic Operators

➗ C++ Arithmetic Operators – Add, Subtract, Multiply & More

Arithmetic operators help you do math in C++. Think of them as your personal calculator keys 🔢!

Let’s see what operations you can perform:

🔢 Basic Arithmetic Operators

  • + – Addition
  • - – Subtraction
  • * – Multiplication
  • / – Division
  • % – Modulus (remainder after division)

🔍 Example: Basic Arithmetic in Action

#include <iostream>
using namespace std;

int main() {
    int a = 15, b = 4;

    cout << "Addition: " << a + b << endl;
    cout << "Subtraction: " << a - b << endl;
    cout << "Multiplication: " << a * b << endl;
    cout << "Division: " << a / b << endl;
    cout << "Modulus: " << a % b << endl;

    return 0;
}

Try It Now

⚠️ Note:

  • If both numbers are integers, division / will give an integer result. For example, 5 / 2 will return 2.
  • To get decimal values, use float or double.

🧪 Example: Decimal Division

#include <iostream>
using namespace std;

int main() {
    float a = 5;
    float b = 2;

    cout << "Decimal Division: " << a / b << endl;

    return 0;
}

Try It Now