C++ Arithmetic Operators

In C++, operators are symbols used to manipulate variables and values. They allow programs to perform calculations, comparisons, and logical evaluations.

Tutorials dojo strip



Using the Addition Operator (+)

Operators can be used to perform simple arithmetic operations. For example:

#include <iostream>
using namespace std;

int main() {
    int topSpeed = 200 + 50;  // Adding two values
    cout << "Top speed is: " << topSpeed << " km/h";
    
    return 0;
}

This program adds 200 and 50, storing the result (250) in topSpeed.

Operators can also combine variables and values, or multiple variables:

#include <iostream>
using namespace std;

int main() {
    int torque1 = 80 + 20;  // 100 (80 + 20)
    int torque2 = torque1 + 50;  // 150 (100 + 50)
    int totalTorque = torque2 + torque2;  // 300 (150 + 150)

    cout << "Total torque is: " << totalTorque << " Nm";
    
    return 0;
}




Types of Operators in C++

C++ organizes operators into different categories:

  • Arithmetic Operators → Perform mathematical calculations.
  • Assignment Operators → Assign values to variables.
  • Comparison Operators → Compare values.
  • Logical Operators → Control decision-making logic.
  • Bitwise Operators → Perform operations on binary values.




Arithmetic Operators

Arithmetic operators allow for common mathematical operations.

OperatorNameDescriptionExample
+AdditionAdds two valuesx + y
-SubtractionSubtracts one value from anotherx - y
*MultiplicationMultiplies two valuesx * y
/DivisionDivides one value by anotherx / y
%ModulusReturns the remainder of divisionx % y
++IncrementIncreases a variable’s value by 1++x
--DecrementDecreases a variable’s value by 1--x
Tutorials dojo strip
Scroll to Top