Operators in C++ Part 1
Introduction
Learning about values, and variables and printing them is not enough for real-world programs, we tend to perform several operations on them.
Let's assume you have 13 candies
and you want to distribute them among 5 students
, How could you find the number of candies each student get and the remaining candies with you?
We will use basic mathematics by dividing and finding the quotient and remainder.
So we have to do some operations between 13 and 5 which are called as values/operands and /
is Divisional Operator.
Operators are symbols that perform operations on variables and values. For example,+
is an operator used for addition, while-
is an operator used for subtraction.
Types of Operators
Operators in C++ can be classified into 6 types:

Arithmetic Operators
Arithmetic operators are used for performing arithmetic operations such as addition, subtraction, etc. Here's a list of operators we will learn in this lesson.

Let's understand it with an example :
Output:
Important Points:
-
45/10 prints 4 not 4.5 just because 45 and 10 both are integer value therefore answer is also only integer part of the actual answer.
-
45%10 leaves a remainder as 5.
-
10%45 would leave a remainder as 10 as no division is done and complete 10 is a remainder.
Division using floating point numbers
Output:
Now let's see increment and decrement arithmetic operators.
Output :
Num value 10 is being increment by 1 makes it 11 and then decrement by 1 leading it to 10 again.
num++ is equivalent to num = num + 1 .
num - - is equivalent to num = num-1 .
Increment and Decrement operator is further classified as :
1 . Post Increment
In post increment value is being initialised or printed firstly and then the value is being incremented by 1.
Output:
Due to post - increment firstly original value of num 90 is being printed and then it is being increment to 91.
2. Pre Increment
In pre increment value is being incremented by 1 firstly then it is being printed or initialised to other variable.
Output :
Due to pre - increment firstly value is being incremented by 1 to 91 and then printed and original value is now 91.
Quiz
What is the output of the following code?
What is the output of the following code?
Practice
1 .Create a program to find the area of square having side of 8.7 units.
2 .Create a program to divide N candies to M number of students. Suppose you have to divide 18 candies among 4 students equally.How many candies will each student get if candies must be divided equally?
And how many candies will be left that cannot be divided?
In this lesson we have discussed Arithmetic operators and all its types , in next lesson we will discuss about Relational , Assignment , Logical , Bitwise and some special operators.
Coding is the art of making numbers dance, and in C++, arithmetic operators are the choreographers, orchestrating the graceful steps of calculation
Join Our Course

Offer ends in:
Days
Hours
Mins
Secs