Course Content
C++ Tutorial
About Lesson

Arithmetic Operators

Arithmetic operators form the foundation of mathematical operations in C++, enabling manipulation of numerical values within programs. They include addition, subtraction, multiplication, division, and modulus operators.

Addition Operator (+)

The addition operator, represented by “+”, combines two values to produce their sum. For example:

int a = 5;
int b = 3;
int sum = a + b; // sum will be 8

Subtraction Operator (-)

The subtraction operator, “-“, subtracts the second operand from the first. Example:

int x = 10;
int y = 4;
int difference = x - y; // difference will be 6

Multiplication Operator (*)

The multiplication operator, “*”, performs multiplication between two operands. Example:

int p = 6;
int q = 7;
int product = p * q; // product will be 42

Division Operator (/)

The division operator, “/”, divides the first operand by the second. Example:

float m = 20.0;
float n = 4.0;
float result = m / n; // result will be 5.0

Modulus Operator (%)

The modulus operator, “%”, returns the remainder of the division operation. Example:

int num1 = 17;
int num2 = 5;
int remainder = num1 % num2; // remainder will be 2

Operator Precedence and Parentheses

Understanding operator precedence helps control the sequence of operations. Parentheses can be used to prioritize certain calculations. Example:

int value = (10 + 5) * 3; // value will be 45 (15 * 3)