Notes For Chapter 3
Notes For Chapter 3
Operators are special symbols which are used to perform various mathematical calculations.
Types of C++ operators
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators.
5. Increment and Decrement Operators
Arithmetic Operators:
Operator Description
== equal
!= Not equal
> Greater than
< Less than
>= Greater than equal
<= Less than equal
Logical Operator
Operato
Description
r
&& Called Logical AND operator
|| Called Logical OR Operator.
! Called Logical NOT Operator.
Operator Description
= Simple assignment operator
+= Add AND assignment operator Assignment operators
-= Subtract AND assignment operator
*= Multiply AND assignment operator
/= Divide AND assignment operator
%= Modulus AND assignment operator,
<<= Left shift AND assignment operator
>>= C o AND
Right shift m p assignment
i l e d B y operator
: Angel Deepak Godson Page 3|8
&= Bitwise AND assignment operator
^= bitwise exclusive OR and assignment operator
|= bitwise inclusive OR and assignment operator
Increment and Decrement Operator
WORKSHEET 1
a. f = ++i - j; _______________________
b. f = i++ - j; _______________________
WORKSHEET 2
Q.1 Write the expressions using relational operator that following statements mean.
a. Check if x is not equal to 9.
b. Check if x is equal to y.
c. Check if d is less than or equal to e.
d. Check if t is greater than or equal to 10.
Q.2 Given,
int e1=0, e2=5
What is the result of each of the following expressions?
Q.4 Using the given values of x,y and z evaluate the following.
(x == y) || (! (z == y) && (z < x))
a. x = 10, y = 10, z = 1 _____________________________
b. x = 0, y = 10, z = 10 _____________________________
c. x = 1, y = 1, z = 1 _____________________________
Q. 5 Using the given values of x,y and z evaluate the following.
(x + y) || (! (z == y) && (z < x++))
a. x = 10, y = 10, z = 1 _____________________________
b. x = 0, y = 10, z = 10 _____________________________
c. x = 1, y = 1, z = 1 _____________________________
Q.8 Find the error in the given expression and rewrite the corrected one.
a. int a,b,c,d;
cin >> a >> b >> c;
d = a + bc;
b. int x,y;
cin >> x >> y;
cout << x=>y;
c. float p,q;
cout << p%q;
d. int a,b;
a=+b;
cout <<a;