What are Arithmetic Operators in C++ | Definition | Types | Examples (2024)

An Operator is a symbol which behaves like a function, that tells the computer or the compiler to perform some mathematical operations on variable and values. Operators are used in programming in order to manipulate data and variables. C++ has a predefined set of different Operators. One such commonly used Operator is the Arithmetic Operators. Let us learn about it in detail.

What are Arithmetic Operators in C++ | Definition | Types | Examples (1)

Definition

In C++, Arithmetic Operators are symbols used to perform common arithmetic operations like addition, subtraction, multiplication, division, modulus, etc.

Arithmetic Operators are operators which are used within the equation to perform a number of basic mathematical calculations.

Arithmetic Operators

Arithmetic Operators use a specific symbol in order to be used within the program. Arithmetic Operators use two operands and an operator between them in order to calculate the result. Arithmetic Operators are simply sign’s which we use in the mathematical equations in order to compute results.

Basic Arithmetic Operators in C++ are listed below:

OperatorMeaningExample
+Addition of variables/values5 + 10 = 15
Subtraction10 – 4 = 6
*Multiplication3 * 20 = 60
/Division40 / 5 = 8
%Modulus which indicates remainder in a division operator40 % 10 = 0

Although the Arithmetic Operators are often used to calculate results between 2 values, they can also be used between 2 variables.

Let us understand this by taking an example:

 
int a = 10 - 4 ; // a = 6int b = a * 3 ; // b = 18int c = a + b ; // c = 24

Let’s look at each Arithmetic Operator Separately

Addition Operator

Addition Arithmetic Operators are used to add 2 values and variables in a program statement. The symbol used for this type of operator is ‘+’. In simple words, Addition combines 2 numbers.

Example

 
int main(){int a, b;a = 10;b = 5;cout << "a + b = " << (a + b) << endl ;}

Output

 
a + b = 15

Browse all the Topics UnderOperator and Expressions: Operators

  • Assignment Operator
  • C++ Shorthands
  • Unary Operator
  • Increment and Decrement Operators
  • Relation Operator
  • Logical Operators

Subtraction Operator

Subtraction Arithmetic Operator is used to subtract 2 values or variables in the program. The symbol used for this operator is ‘-’.

Example

 
int main(){int a, b;a = 10;b = 5;cout << "a - b = " << (a - b) << endl ;}

Output

 
a - b = 5

Multiplication Operator

This operator is denoted by the ‘*’ or ‘x’ symbol. It gives the product of two numbers.

Example

 
int main(){int a, b;a = 10;b = 5;cout << "a * b = " << (a * b) << endl ;}

Output

 
a * b = 50

Division Operator

This Arithmetic Operator divides its first operand by the second operand. It is denoted by the ‘/’ symbol. In C++, if we divide An Integer with another Integer then we will get the Quotient as the result. But if either of the operands is a floating-point number, then the result of division will be in Decimals.

Example

In C++

 
int a = 7 / 2 ; // a = 3int b = 7.0 / 2 ; // b = 3.5int c = 7 / 2.0 ; // c = 3.5

Modulus Operator

This type of Arithmetic Operator computes the remainder of the two values when divided. The symbol used to define this operator is ‘%’. Both the operands must be integer type only. If they are of the floating-point type, then there might arise a compile-time error.

Example

 
int main(){int a = 12 ;int b = 5 ;cout << "c = " << (a % b) << endl ;}

Output

Order of Operations

There can rise an issue when an operand has to be computed with 2 or more other operands at the same time. When more than one operator is applied to the same operand, C++ uses the rules of precedence to decide which operator actions to be applied first.

For example

int speed = 12 * 5 + 34 ;

Here the value of speed can be either 94 or 468.

In this above example, we can see that Value 5 is an operand for both the * and + operators. In this situation, C++ follows the Precedence Rules.

The Precedence Rules states that in such situations, the sequence to compute the value is multiplication, division, then modulus before the addition and subtraction mathematical operations.

FAQs onArithmetic Operators

Q1. What is the output of this program?

 
intmain(){inta;a = 10 + 2 * 5;cout <<a;return0;}
  1. 20
  2. 30
  3. 60
  4. 80

Answer. Option A. * operator has higher precedence than + operator.

Q2. What is the output of the following line of statement?

int count = 10.5 / 5 ;

  1. 2
  2. 0
  3. 1
  4. None of the above

Answer. Option C.

Q3. The operator that takes 2 operands is?

  1. Unary
  2. Binary
  3. Ternary
  4. None

Answer. Option B

Q4. Arithmetic Operators provided by C++ are?

  1. Modulus %
  2. Equate =
  3. Addition +
  4. Both A and C

Answer. Option D

What are Arithmetic Operators in C++ | Definition | Types | Examples (2024)

FAQs

What are Arithmetic Operators in C++ | Definition | Types | Examples? ›

Arithmetic Operators in C++ are used to perform arithmetic or mathematical operations on the operands. For example, '+' is used for addition, '–' is used for subtraction, '*' is used for multiplication, etc.

What are the arithmetic operators? ›

Arithmetic Operators
OperatorMeaning
*Multiplication: multiply two values
/Division: divide one value by another
+Addition: add two values
Subtraction: subtract one value from another
2 more rows

What are arithmetic assignment operators in C++? ›

Arithmetic Operators
OperatorNameDescription
/DivisionDivides one value by another
%ModulusReturns the division remainder
++IncrementIncreases the value of a variable by 1
--DecrementDecreases the value of a variable by 1
3 more rows

What is += called in C++? ›

12. Addition assignment (+=) The addition assignment operator adds the value of the right operand to the value of the left operand, then assigns the result back to the left operand.

What are the six types of operators in C++? ›

Operators in C++ can be classified into 6 types:
  • Arithmetic Operators.
  • Assignment Operators.
  • Relational Operators.
  • Logical Operators.
  • Bitwise Operators.
  • Other Operators.

What are the 5 basic arithmetic operations? ›

The arithmetic operators perform addition, subtraction, multiplication, division, exponentiation, and modulus operations.

What is an example of an arithmetic operator in C? ›

Arithmetic Operator is used to performing mathematical operations such as addition, subtraction, multiplication, division, modulus, etc., on the given operands. For example: 5 + 3 = 8, 5 - 3 = 2, 2 * 4 = 8, etc. are the examples of arithmetic operators.

What are the arithmetic operators in C++? ›

Arithmetic Operators
OperatorMeaningExample
+Addition of variables/values5 + 10 = 15
Subtraction10 – 4 = 6
*Multiplication3 * 20 = 60
/Division40 / 5 = 8
1 more row

What is operator in C++ with example? ›

5) Assignment Operators
NamemultiplySymbolExample
Assignment Operator=int a = 2; // a = 2
Add and Assignment Operator+=int a = 2, b = 4; a+=b; // a = 6
Subtract and Assignment Operator-=int a = 2, b = 4; a-=b; // a = -2
Multiply and Assignment Operator*=int a = 2, b = 4; a*=b; // a = 8
1 more row
Jun 7, 2024

Is == an assignment operator? ›

The = is an assignment operator, while == and === are called equality operators.

What does == mean in C++? ›

Equality operators: == and !=

The result type for these operators is bool . The equal-to operator ( == ) returns true if both operands have the same value; otherwise, it returns false . The not-equal-to operator ( !=

What does C++ stand for? ›

C++ (or “C-plus-plus”) is a generic programming language for building software. It's an object-oriented language. In other words, it emphasizes using data fields with unique attributes (a.k.a. objects) rather than logic or functions.

What does *= mean in C++? ›

*= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand. C *= A is equivalent to C = C * A.

What is |= in C++? ›

7. Bitwise OR Assignment Operator (|=) The bitwise OR assignment operator performs a bitwise OR between the variable on the left and the value or variable on the right and assigns the result to the variable on the left.

What does exclamation mark mean in C++? ›

The ! operator negates, or reverses the truth value of, the expression that follows it. That is, if expression is true , then ! expression is false —and vice versa.

What does || do in C++? ›

The logical OR operator ( || ) returns the boolean value true if either or both operands is true and returns false otherwise.

What are the 6 arithmetic operations? ›

These operators are + (addition), - (subtraction), * (multiplication), / (division), and % (modulo). The following table summarizes the binary arithmetic operations in the Java programming language.

What are the 4 arithmetic operations? ›

A major part of elementary school mathematics is dedicated to the four fundamental operations of arithmetic—addition, subtraction, multiplication and division.

What are the five arithmetic operators they are * and _______? ›

The arithmetic operators for scalars in MATALB are: addition (+), subtraction (−), multiplication (*), division (/), and exponentiation (^). Vector and matrix calculations can also be organized in a simple way using these operators. For example, multiplication of two matrices A and B is expressed as A * B.

What are the six Excel arithmetic operators? ›

Diverse Types of Excel Operators
  • Arithmetic Operators. Plus (+) Minus (-) Multiply (*) Divide (/) Power (^)
  • Comparison Operators. Equal to (=) Greater than (>) Less than (<) Greater than or equal to (>=) ...
  • Text Concatenation Operator (&)
  • Reference Operators. Range Operator (:) Union Operator (,) Intersection Operator ( )

Top Articles
Latest Posts
Article information

Author: Kieth Sipes

Last Updated:

Views: 6180

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.