Lecture - 15-16
Lecture - 15-16
Programming Fundamentals
BS Information Technology –
First Semester
Operands
3
Types of
Operators
Unary Operators
• Perform operation on one
operand
Binary Operators
• Perform operation on two
operands
4
Categories of Operators in
C++
• Arithmetic Operators ( + , - , / , * , %)
• Assignment Operator ( = )
• Arithmetic Assignment Operators ( += , -= , /= , *= ,
• Relational Operators ( > , < , >= , <= , == %=)
, !=)
• Logical Operators ( && , | | , ! )
• Increment and Decrement Operators ( ++ , -
-)
5
Arithmetic Operators in
C++
• They perform arithmetic operations on the
program data.
6
Arithmetic Operators in
C++
• Addition, Subtraction, Multiplication and Division
operations can be performed on integer numbers as well
as floating point numbers.
7
Arithmetic Operators in
C++
8
Assignment Operator in
C++
• Assignment operator assigns a constant value, a variable or
equation to a
single variable.
• There is one assignment operator ( = ). It is binary
operator.
• It assigns anything on its right side to its left side.
float radius = a = c = ( f – 32 ) /
6.98 ; b; 1.8 ;
= Assignment
Operator 9
Assignment Operator in
C++
10
Arithmetic Assignment Operators
in C++
• They perform arithmetic operations on two operands and assigns
the resultant in the same first operand.
11
Arithmetic Assignment Operators
in C++
a += b is same as a = a+
b
a = a+
First operand = a
b
Second operand = b
Result stored back in to first operand i.e.
a
12
Arithmetic Assignment Operators
in C++
13
Relational Operators in
C++
• They compare two operands and return 0 or 1. If comparison is
successful, they return 1 else return 0. They are used to create
conditions. One relational operator creates one condition.
Operation Description Example
> Greater Than a>b
== Equals To a == b
!= Not Equals To a != b
14
Relational Operators in
C++
15
Logical Operators in
C++
• They perform logical operations on the logical operands. They return
either 0 or 1.
• They combine multiple conditions to form one composite condition.
16
Logical Operators in
C++
a b a && b a b a||b
0 0 0 a !a 0 0 0
0 1 0 0 1 0 1 1
1 0 0 1 0 1 0 1
1 1 1 1 1 1
17
Logical Operators in
C++
18
Logical Operators in
C++
• Logical AND is also called as Short Circuit AND operator.
If the first operand is false ( 0 ) then it will not check the second operand.
• Logical OR is also called as Short Circuit OR operator.
If the first operand is true ( 1 ) then it will not check the second operand.
20
Increment & Decrement
Operators in
C+
+
21