C++ Language 
By:-AAKASH KAUSHIK 
#9289817971, 98919893083 
Email-theaakashkumar@gmail.com
UNIT -4 
OPERATORS & 
EXPRESSIONS
OPERATORS 
An operator is a symbol that tells the compiler 
to perform specific mathematical or logical 
manipulations. 
operators operates on some data to give 
results 
For ex :- A+B=C 
Here A, B are operands and + is the 
operator which produces C as a result of addition 
of A and B. 
AAKASH KAUSHIK 
9891983083,9289817971
CLASSIFICATION OF OPERATORS 
Based on the no. of operand needed for 
operation operators can be broadly classified into 
3 categories. 
UNARY OPERATORS 
BINARY OPERATORS 
TERNARY OPERATORS 
AAKASH KAUSHIK 
9891983083,9289817971
UNARY OPERATORS 
The unary operators operate on a 
single operand
UNARY PLUS(+) & UNARY MINUS(-) 
UNARY (–) MINUS – used to represent –ive 
values. 
ex.:- -5,-50,-3.14 etc. 
UNARY (+) PLUS – used to represent +ive 
values. 
ex.:- +5,+50,+3.14 etc. 
In C++ by default values are considered as +ive 
so no need to explicitly use UNARY (+)PLUS. 
AAKASH KAUSHIK 
9891983083,9289817971
INCREMENT/DECREMENT OPERATOR 
Increment operator increases integer value by one. 
For ex.:- 
int a=10; 
a++; //will give 11 
Decrement operator decreases integer value by one. 
For ex.:- 
int a=10; 
a--; //will give 9 
AAKASH KAUSHIK 
9891983083,9289817971
BINARY OPERATORS 
The Binary operator takes 2 
arguments.
TYPE OF BINARY OPERATORS 
ARITHMETIC OPERATORS 
RELATIONAL OPERATORS 
LOGICAL OPERATORS 
AAKASH KAUSHIK 
9891983083,9289817971
ARITHMETIC OPERATORS 
Arithmetic operators are used for mathematic 
calculations. 
AAKASH KAUSHIK 
9891983083,9289817971
RELATIONAL OPERATORS 
A relational operator compares two operands to 
determine whether one is greater than, greater 
than or equal to, less than, less than or equal to 
the other. 
If the condition is true, it will return non-zero 
value, if the condition is false, it will return 0. 
AAKASH KAUSHIK 
9891983083,9289817971
RELATIONAL OPERATORS 
AAKASH KAUSHIK 
9891983083,9289817971
LOGICAL OPERATORS(AND,OR,NOT) 
Logical operators are used in situation when 
we have more then one condition in a single 
statement. 
The logical operators && and || are used when 
evaluating two expressions to obtain a single 
relational result. 
The logical operator ! Is used for negation 
purpose. Basically, it returns the opposite 
Boolean value of evaluating its operand. 
AAKASH KAUSHIK 
9891983083,9289817971
LOGICAL OPERATORS 
AAKASH KAUSHIK 
9891983083,9289817971
TERNARY OPERATORS 
THE ONE AND ONLY TERNARY 
OPERATOR IS CONDTIONAL 
OPERATOR( ? : )
CONDITIONAL OPERATOR 
The conditional operator is also known as 
ternary operator. It is called ternary operator 
because it takes three arguments. First is 
condition, second and third is value. The 
conditional operator check the condition, if 
condition is true, it will return second value, if 
condition is false, it will return third value. 
Syntax:- 
val = condition ? val1 : val2; 
AAKASH KAUSHIK 
9891983083,9289817971
TERNARY OPERATOR USAGE 
EXAMPLE 
#include<iostream.h> 
#include<conio.h> 
void main() 
{ 
clrscr(); 
int x=5,y=2,lrg; 
lrg = (x>y) ? x : y; 
cout<<"nlargest number is : "<<lrg; 
getch(); 
} 
Output : Largest number is : 5 
AAKASH KAUSHIK 
9891983083,9289817971
SOME MORE SPECIAL OPERATORS 
SIZEOF & COMMA OPERATOR
SIZEOF OPERATOR 
The sizeof is a compile time operator, and used 
with an operand, it returns the number of bytes 
the operand occupies. The operand may be a 
variable, a constant or a data type qualifier. 
m=sizeof(sum); 
n=sizeof(long int); 
k=sizeof(235L); 
AAKASH KAUSHIK 
9891983083,9289817971
COMMA OPERATOR(,) 
The comma operator (,) is used to separate two 
or more expressions that are included where 
only one expression is expected. When the set of 
expressions has to be evaluated for a value, only 
the right-most expression is considered. 
For example, the following code: 
a = (b=3, b+2); 
would first assign the value 3 to b, and then 
assign b+2 to variable a. So, at the end, 
variable a would contain the value 5 while 
variable b would contain AAKASH KAUSHIK 
value 3. 
9891983083,9289817971
THANK 
YOU 
AAKASH KAUSHIK 
9891983083,9289817971

c++ programming Unit 4 operators

  • 1.
    C++ Language By:-AAKASHKAUSHIK #9289817971, 98919893083 Email-theaakashkumar@gmail.com
  • 2.
    UNIT -4 OPERATORS& EXPRESSIONS
  • 3.
    OPERATORS An operatoris a symbol that tells the compiler to perform specific mathematical or logical manipulations. operators operates on some data to give results For ex :- A+B=C Here A, B are operands and + is the operator which produces C as a result of addition of A and B. AAKASH KAUSHIK 9891983083,9289817971
  • 4.
    CLASSIFICATION OF OPERATORS Based on the no. of operand needed for operation operators can be broadly classified into 3 categories. UNARY OPERATORS BINARY OPERATORS TERNARY OPERATORS AAKASH KAUSHIK 9891983083,9289817971
  • 5.
    UNARY OPERATORS Theunary operators operate on a single operand
  • 6.
    UNARY PLUS(+) &UNARY MINUS(-) UNARY (–) MINUS – used to represent –ive values. ex.:- -5,-50,-3.14 etc. UNARY (+) PLUS – used to represent +ive values. ex.:- +5,+50,+3.14 etc. In C++ by default values are considered as +ive so no need to explicitly use UNARY (+)PLUS. AAKASH KAUSHIK 9891983083,9289817971
  • 7.
    INCREMENT/DECREMENT OPERATOR Incrementoperator increases integer value by one. For ex.:- int a=10; a++; //will give 11 Decrement operator decreases integer value by one. For ex.:- int a=10; a--; //will give 9 AAKASH KAUSHIK 9891983083,9289817971
  • 8.
    BINARY OPERATORS TheBinary operator takes 2 arguments.
  • 9.
    TYPE OF BINARYOPERATORS ARITHMETIC OPERATORS RELATIONAL OPERATORS LOGICAL OPERATORS AAKASH KAUSHIK 9891983083,9289817971
  • 10.
    ARITHMETIC OPERATORS Arithmeticoperators are used for mathematic calculations. AAKASH KAUSHIK 9891983083,9289817971
  • 11.
    RELATIONAL OPERATORS Arelational operator compares two operands to determine whether one is greater than, greater than or equal to, less than, less than or equal to the other. If the condition is true, it will return non-zero value, if the condition is false, it will return 0. AAKASH KAUSHIK 9891983083,9289817971
  • 12.
    RELATIONAL OPERATORS AAKASHKAUSHIK 9891983083,9289817971
  • 13.
    LOGICAL OPERATORS(AND,OR,NOT) Logicaloperators are used in situation when we have more then one condition in a single statement. The logical operators && and || are used when evaluating two expressions to obtain a single relational result. The logical operator ! Is used for negation purpose. Basically, it returns the opposite Boolean value of evaluating its operand. AAKASH KAUSHIK 9891983083,9289817971
  • 14.
    LOGICAL OPERATORS AAKASHKAUSHIK 9891983083,9289817971
  • 15.
    TERNARY OPERATORS THEONE AND ONLY TERNARY OPERATOR IS CONDTIONAL OPERATOR( ? : )
  • 16.
    CONDITIONAL OPERATOR Theconditional operator is also known as ternary operator. It is called ternary operator because it takes three arguments. First is condition, second and third is value. The conditional operator check the condition, if condition is true, it will return second value, if condition is false, it will return third value. Syntax:- val = condition ? val1 : val2; AAKASH KAUSHIK 9891983083,9289817971
  • 17.
    TERNARY OPERATOR USAGE EXAMPLE #include<iostream.h> #include<conio.h> void main() { clrscr(); int x=5,y=2,lrg; lrg = (x>y) ? x : y; cout<<"nlargest number is : "<<lrg; getch(); } Output : Largest number is : 5 AAKASH KAUSHIK 9891983083,9289817971
  • 18.
    SOME MORE SPECIALOPERATORS SIZEOF & COMMA OPERATOR
  • 19.
    SIZEOF OPERATOR Thesizeof is a compile time operator, and used with an operand, it returns the number of bytes the operand occupies. The operand may be a variable, a constant or a data type qualifier. m=sizeof(sum); n=sizeof(long int); k=sizeof(235L); AAKASH KAUSHIK 9891983083,9289817971
  • 20.
    COMMA OPERATOR(,) Thecomma operator (,) is used to separate two or more expressions that are included where only one expression is expected. When the set of expressions has to be evaluated for a value, only the right-most expression is considered. For example, the following code: a = (b=3, b+2); would first assign the value 3 to b, and then assign b+2 to variable a. So, at the end, variable a would contain the value 5 while variable b would contain AAKASH KAUSHIK value 3. 9891983083,9289817971
  • 21.
    THANK YOU AAKASHKAUSHIK 9891983083,9289817971