Arithmetic operators are used to perform mathematical operations. All operators used
integer & floating-point data type except remainder or modulas operator.
Operator
Example
OPERATORS INC++:
Operators are the symbols which tell the computer to execute certain mathematical or
logical operations. A mathematical or logical expression is generally formed with the help
of an operator. C++ programming offers a number of operators which are classified into the
following categories.
Arithmetic Operators
a % b
a/b
a b
a-b
a+b
#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
intmain()
int a, b, add, sub, mul, rem;
float div;
cout<<“\n \t SIMPLE CALCULATOR”;
cout<<“\n \t Enter the value of a…”;
cin >> a;
adamjeecoaching.blogspot.com
cout<<“\n \t Enter the value of a…”;
cin >> b;
add = a+b;
cout<<“\n \t Addition of “<< a << “and” << b
sub-a-b;
cout<<“\n \t Subtraction of “<< a <<
mul = a* b;
<<b<< “is”<< sub;
cout<<“\n \t Multiplication
div = a/b;
cout << “\n \t Division
rem-a % b;
cout<<“\n \t
a << “and” << b << “is”<< mul;
a << “and” << b<< “is” <<div;
ainder of “<< a << “and” << b << “is” << rem;
OUTPUT:
SIMPLE CALCULATOR:
Enter the value of a 30
Enter the value of b 20
Addition of 30 and 20 is 50
Subtraction of 30 and 20 is 10
Multiplication of 30 and 20 600
Division of 30 and 20 is 1
Remainder of 30 and 20 is 10
C++ provides the unary increment operator. It is used to be incremented a variable by 1.
Increment operator represented by ++ (double plus sign). The increment operators are
used in two ways (postfix & Prefix) summarized below:
Operators Explanation
++a
(Prefix)
a++
Increment a by 1, then use the new value of a in the expression in
resides.
Use the current value of a in the expression in which a resides, then
(Postfix) increment a by 1.
EXAMPLE (PREFIX) coaching.blogspot.com
#include<iostream>
using namespace std;
int main()
Value of ch is 6
int ch = 5;
cout<<“\n Value of ch is :”<<++cl
return 0;
EXAMPLE (POSTFIX)
cout<<“\n Value of ch is :”<< ch++;
return 0;
OUTPUT
Value of ch is 5
C++ also provides the unary decrement operator. It is used to be decremented a variable
by 1. decrement operator represented by — (double minus sign). The decrement operators
are used in two ways (postfix & Prefix) summarized below:
Operators Explanation
-a
(Prefix)
Decrement a by 1, then use the new value of a in the expression which a
resides.
a-
Use the current value of a in the expression in whic
(Postfix) decrement a by 1.
resides, then
Relational operators are used when we have to make comparisons. It is used to test the
relation between two values. The result of comparison is True (1) or False (0). C++
programming offers following relational operators:
Operator
value on left is less than value on right.
the value on left is greater than value on right.
It checks the value on left is less than or equal to value
on right.
It checks the value on left is greater than or equal to
value on right.
Example
a<b
a> b
a <= b
a >= b
It checks the equality of two values.
a == b
It checks the value on left is not equal to value on right.
a != b
#include<iostream>
using namespace std;
int main()
int x = 20, y = 10;
if(x > y)
cout << “X is greater than Y”;
else
cout << “Y is greater than X”;
return 0;
OUTPUT
X is greater than Y
adamjeecoaching.blogspot.com
Logical operators are used when more than one conditions are to be tested and based on
that result, decisions have to be made. C++ programming offers three logical operators.
They are:
Operator
Operations
Expression
Logical AND. The condition will be true
if both expressions are true.
Logical OR. The condition will be true if
anyone of the expressions are true.
Logical NOT. The condition, will be
inverted, False becomes true & true
becomes false.
1 if a==b && c == d; else 0
1 if a b || c>d; else 0
1 if !(a == 0); else 0
PROGRAM USING LOGICAL OPERATORS INC+
#include<iostream>
#include<conio.h>
using namespace std;
int main()
OUTPUT:
Logical Operators Example
Num1 is less than and Num2 is greater than or
equal to 40
Num 1 or Num 2 is greater than or equal to 40
int num1 = 30, num2 = 40;
cout << “Logical Operators Example \n”;
if(num1<=40 && num2>=40)
cout << “Num1 is less than and Num2 is greater than or equal to 40 \n”;
adamjeecoaching.blogspot.com
if(num1 >=40 | | num2 >= 40)
cout << “Num 1 or Num 2 is greater than or equal to 40 \n”;
getch();
return 0;
Assignment operator (=) are used to assign result of an expression or a value to a variable.
The associativity of assignment operators is right to left means value or expression at the
right is assigned to the left side variable.
Arithmetic assignment operator is a combination of arithmetic. and assignment operators.
This operator first performs an arithmetic operation on the current value of the variable on
left to the value on the right and then assigns the result to the variable on the left.
OPERATOR
+= (Addition-Assignment)
-=(Subtraction-Assignment)
(Multiplication-Assignment)
/= (Division-Assignment)
DESCRIPTION
Adds the right operand to the left and assigns the
result to the left operand.
Subtracts the right operand to the left and assigns the
result to the left operand.
Multiplies the right operand to the left and assigns the
result to the left operand.
Divides the right operand to the left and assigns the
result to the left operand.
PROGRAM USING ASSIGNMENT & ARITHMETIC ASSIGNMENT OPERATORS IN C+
#include<conio.h>
using namespace std;
int main()
int a = 10;
cout << “Value of a using assignment operator is “<< a << “\n”;
a += 10;
cout << “Value of a using addition assignment operator is “<< a << “\n”;
a -= 10;
cout << “Value of a using subtraction assignment operator is “<< a << “\n”;
a* = 10;
cout << “Value of a using multiplication assignment operator is “<< a << “\n”;
a/= 10;
cout << “Value of a using division assignment operator is “<< a << “\n”;
return 0;
OUTPUT
Value of a using assignment operator is 10
Value of a using addition assignment operator is 20
Value of a using subtraction assignment operator is 10
adamje Value of a using multiplication assignment operator is 100
Value of a using division assignment operator is 10
0 of 10 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 10 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
What is the purpose of arithmetic operators in C++?
Which statement accurately describes the increment operator in C++?
What is the output of the following code snippet in C++?
cppCopy code
int x = 5; cout << “Value of x is : ” << x++;
Which category of operators is used to test the relation between two values in C++?
What is the output of the following code snippet in C++?
cppCopy code
int num1 = 30, num2 = 40; if (num1 >= 20 || num2 <= 50) cout << “Condition satisfied”; else cout << “Condition not satisfied”;
Which statement accurately describes the difference between relational and logical operators in C++?
What is the purpose of assignment operators in C++?
cppCopy code
int a = 10; a += 5; cout << “Value of a is : ” << a;
Which statement accurately describes the behavior of the decrement operator in C++?
Which operator is used to assign the result of an expression or a value to a variable in C++?