In this tutorial, we will learn about different Arithmetic Operators available in C++ programming language and go through each of these Arithmetic Operators in detail, with the help of examples.
C++ Arithmetic Operators
Arithmetic Operators are used to perform common mathematical operations like addition, subtraction, multiplication, division, etc.
Tutorials
- C++ Addition Operator This arithmetic operator returns the sum of given two operands.
- C++ Subtraction Operator This arithmetic operator returns the difference of second operand from the first operand.
- C++ Multiplication Operator This arithmetic operator returns the product of the given two operands.
- C++ Division This arithmetic operator returns the quotient of the division of first operand by second operand.
- C++ Modulus Operator This arithmetic operator returns the remainder of the division of the first operand by the second operand.
- C++ Increment Operator This arithmetic operator increments the value of given operand by one.
- C++ Decrement Operator This arithmetic operator decrements the value of given operand by one.
Arithmetic Operators
The following table specifies symbol, example, and description for each of the Arithmetic Operator in C++.
Arithmetic Operation | Operator Symbol | Example | Description |
---|---|---|---|
Addition | + | a + b | Returns sum of a and b . |
Subtraction | – | a – b | Returns difference of b from a . |
Multiplication | * | a * b | Returns product of a and b . |
Division | / | a / b | Returns the quotient when a is divided by b . |
Modular Division | % | a % b | Returns reminder when a is divided by b . |
Increment | ++ | a++ or ++a | Increments the value of a by one. |
Decrement | — | a– or –a | Decrements the value of a by one. |
Examples
C++ Addition
+
operator computes the addition of the two operands and returns the result.
main.cpp
#include <iostream>
using namespace std;
int main() {
int a = 12;
int b = 7;
int sum = a + b;
cout << "Addition : " << sum << endl;
}
Output
Addition : 19
Program ended with exit code: 0
Learn more about C++ Addition.
C++ Subtraction
-
operator computes the difference of right operand from left operand and returns the result.
main.cpp
#include <iostream>
using namespace std;
int main() {
int a = 12;
int b = 7;
int diff = a - b;
cout << "Subtraction : " << diff << endl;
}
Output
Subtraction : 5
Program ended with exit code: 0
Learn more about C++ Subtraction.
C++ Multiplication
*
operator computes the product of two operands and returns the result.
main.cpp
#include <iostream>
using namespace std;
int main() {
int a = 12;
int b = 7;
int product = a * b;
cout << "Multiplication : " << product << endl;
}
Output
Multiplication : 84
Program ended with exit code: 0
Learn more about C++ Multiplication.
C++ Division
+
operator computes the division of first operand with second operand and returns the quotient.
main.cpp
#include <iostream>
using namespace std;
int main() {
int a = 16;
int b = 7;
int div = a / b;
cout << "Quotient : " << div << endl;
}
Output
Quotient : 2
Program ended with exit code: 0
Learn more about C++ Division.
C++ Modular Division
%
operator computes the division of the given operands and returns the remainder.
main.cpp
#include <iostream>
using namespace std;
int main() {
int a = 13;
int b = 5;
int modulo = a%b;
cout << "Remainder : " << modulo << endl;
}
Output
Remainder : 3
Program ended with exit code: 0
Learn more about C++ Modular Division.
C++ Increment
++
operator increments the value of the operand by one.
main.cpp
#include <iostream>
using namespace std;
int main() {
int a = 12;
++a;
cout << "Incremented value : " << a << endl;
}
Output
Incremented value : 13
Program ended with exit code: 0
Learn more about C++ Increment.
C++ Decrement
++
operator decrements the value of the operand by one.
main.cpp
#include <iostream>
using namespace std;
int main() {
int a = 12;
--a;
cout << "Decremented value : " << a << endl;
}
Output
Decremented value : 11
Program ended with exit code: 0
Learn more about C++ Decrement.
Conclusion
In this C++ Tutorial, we learned what Arithmetic Operators are, and what they can do, with the help of example C++ programs.