SlideShare una empresa de Scribd logo
1 de 38
Operators and Expressions
What are operators and expressions?
Programs use data stored in variables and perform different types of
operations on that data.
The data on which operations are performed are known as operands and
the types of the operations performed on them are known as operators.
The combination of operators and expressions are known as expressions
Consider the following c++ statement: z * y
z and y are the operands
* (multiplication is the operator
z * y is an expression
Category of Operators
• Based on the number of operands there are three basic types of
operators :
• Unary Operators: they work on a single operand
• Binary Operators: they work on two operands
• Ternary Operators: they work on three operands
Types of Operators
Operators
Arithmetic
Unary
+, -,++, - -
Binary
+, -, *, /, %
Relational
>, <, >=, <=, !=,==
Logical
&&, !, ||
Assignment
=
Special
Conditional
? (true) :false)
C++
Shorthands
+=,-=.*=,/=,%=
Arithmetic operators
• These operators are used
to perform simple
arithmetic calculations
like addition, subtraction ,
multiplication and division
• All the arithmetic
operators are binary in
nature.
• Only the – operator can be
both unary or binary
#include<iostream.h>
void main()
{
int a, b;
a=40, b=20;
cout<<“n Sum of a and b :”<<a+b;
cout<<“n Difference of a and b :”<<a-b;
cout<<“n Product of a and b :”<<a*b;
cout<<“n Quotient of a and b :”<<a/b;
}
Sum of a and b :60
Difference of a and b :20
Product of a and b :800
Quotient of a and b :2
Points to note about arithmetic operators
• They can be used with all data
types.
• The division operator (/) does
integer division only. This means
if we divide say 45 by 6, we will
get the answer as 7 and not 7.5
as expected. This is because the
/ operator discards the decimal
part after division.
• To get the accurate answer in the
above case we must write
45.0/6.0.
#include<iostream.h>
void main()
{
cout<<“Divide one :”<<45/6;
cout<<“n Divide Two :”<<45.0/6.0;
}
Divide one : 7
Divide Two : 7.5
• Another way to get the
accurate result would
be to store the numbers
in float variables.
#include<iostream.h>
void main()
{
float a, b;
a=45, b=6;
cout<<“n a/ b = :”<<a/b;
}
a/b= : 7.5
Points to note about arithmetic operators
The modulus ( % ) operator
The modulus operator , represented by
the percentage sign( %) gives the
remainder of division. For example
2 )25 ( 12 Quotient( 25/2 )
2
5
4
1 Remainder( 25 % 2)
The modulus operator can be used only with integers.
#include<iostream.h>
void main()
{
int a, b;
a=25, b=12;
cout<<“n Quotient of a and b :”<<a/b;
cout<<“n Remainder of division is :”<<a % b;
}
Quotient of a and b :12
Remainder of division is : 1
We can only use the
addition and
subtraction operator
with variables of char
data type.
01
This is possible because
data ( character or
symbol) is stored in a
char variable as an
integer value equal to
the ASCII code of the
character.
02
In the statement:
char ch = ‘A’;
the ASCII equivalent of
‘A’ i.e. 65 is stored in
ch.
03
So if we write
ch=ch+1;We are
actually adding 1 to 65,
which becomes 66. Thus
ch will now store the
letter ‘B’ whose ASCII
code is 66
04
Arithmetic operators and char data
Arithmetic operators and char data
#include<iostream.h>
void main()
{
char ch=‘A’ ;
cout<<“The value of character variable is:”<<ch;
ch=ch+1;
cout<<“n The value after adding 1 :”<<ch;
}
The value of character variable is: A
The value after adding 1 : B
Relational Operators
• Relational operators are used
to form conditions in an
expression.
• They are mainly used to
compare variables with other
variables or constants.
• They are binary in nature
Operator Description Expression
> Greater than a>b
< Less than a<b
>= Greater than or
equal to
a>=b
<= Less than or
equal to
a<=b
== Equal to a==b
!= Not equal to a!=b
Relational Operators
The result of a relational expression is either true(1) or false (0).
Variable value Example Expression Result
a=9, b=8 a>b
a>=b
a==b
a!=b
a>2
True or 1
True or 1
False or 0
True or 1
True or 1
a=9, b=9 a>=b
a==b
a!=b
b>9
True or 1
True or 1
False or 0
False or 0
Using Relational Operators
#include<iostream.h>
void main()
{
int a, b;
a=20, b=12;
cout<<“n a>b =”<<(a>b)<<“t a!=b =“<< (a!=b);
b=b+8;
cout<<“n a>b =”<<(a>b)<<“t a==b =”<<(a==b);
}
a>b = 1 a!=b = 1
a>b = 0 a==b = 1
#include<iostream.h>
void main()
{
int a=2, b=1,c=4,d=6,e=9,f=-6;
cout<<(a>b)<<endl;
cout<<(b>c)<<endl;
cout<<(d<=e)<<endl;
cout<<(e!=f)<<endl;
cout<<(c>=a)<<endl;
cout<<(a==d);
}
1
0
1
1
1
0
Logical Operators
• These operators are used to
combine two or more
conditions.
• They return true or false.
• In the table x and y denote
conditions
Operator Type Example
&& Logical And Binary x && y
|| Logical Or Binary x || y
! Logical Not Unary !x
Working of OR (||) operator
Variable
value
Expression Condition
1
Result Condition
2
Result Output of
expression
x=15, y=7 x>y || y >6 x>y True(1) y>6 True(1) True(1)
x>y || y!= 4 x>y True(1) y!=7 False(0) True(1)
x<y || y==4 x<y False(0) y==7 True(1) True(1)
x<y || y>7 x<y False(0) y>7 False(0) False(0)
Working of AND (&&) operator
Variable
value
Expression Condition
1
Result Condition
2
Result Output of
expression
x=15, y=7 x>y && y >6 x>y True(1) y>6 True(1) True(1)
x>y && y!= 4 x>y True(1) y!=7 False(0) False(0)
x<y && y==4 x<y False(0) y==7 True(1) False(0)
x<y && y>7 x<y False(0) y>7 False(0) False(0)
Working of NOT (!) operator
Variable
value
Expression Condition Result !(Condition ) Output of
expression
x=15, y=4 ! (x>y ) x>y True(1) ! (True ) False(0)
! (y>7) y>7 False(0) ! (False) True(1)
!(x>y || y!= 4) T || F True(1) !(True) False(0)
!(x<y || y>7) F || F False(0) !(False) True(1)
Assignment (=) Operator
The Assignment operator is used to assign a value to a variable.
The variable is always on the left hand side and the value on the right
hand side.
The value can be another variable or an expression.
For eg:
a=b; the value stored in variable b is assigned to a
p=q+r; the sum of q and r is stored in the variable p
X = 20;
Variable Value
In the example the variable x is assigned a value 20.
C++ Shorthands
These are operators used to perform an arithmetic function on an
operand and assign the new value to the operand at the same time.
Operator Description Example Equivalent
to:
+= Addition assignment A+=B A=A+B
-= Subtraction assignment A -=B A=A-B
*= Multiplication assignment A*=B A=A*B
/= Division assignment A/=B A=A/B
%= Modulus assignment A%=B A=A%B
Increment(++) / Decrement(--) Operators
The increment(++) and decrement(--) are unary operators .
The syntax is : Examples:
The increment / decrement operators do not work on constants.
Thus :
variable ++;
or
++ variable;
variable --;
or
-- variable;
a++;
++ x;
p=--q;
t--;
6++; //gives error as 6 is a constant
x=--9; // gives error as 9 is a constant
Increment(++) / Decrement(--) Operators
The increment operator increases the value of a variable by 1
The decrement operator decreases the value of a variable by 1.
Thus and
a++;
is the same as
a=a+1;
b--;
is the same as
b=b-1;
Both the increment and decrement operators can be prefixed or postfixed.
i.e.
In the above statements both prefix and postfix forms do not make any
difference in the output as these are stand alone statements.
But when the pre/post increment or decrement operators are part of an
expression the prefix and postfix notation does matter
++a; (prefix)
is the same as
a++; (postfix)
Increment(++) / Decrement(--) Operators
3
Increment(++) / Decrement(--) Operators
Pre Increment
int a,b;
a=3;
b=++a;
cout<<“a= ”<<a<<“tb= ”<<b;
In the prefix form the increment or decrement operation is carried
out before the rest of the expression.
Consider the following code snippet:
a b a=a+1
b=a
4
a= 4 b= 4
4
1.The value of the variable a is incremented first
2. The new value (4) is assigned to b.
Thus the value of a and b both become 4
1
2
1
2
output
Working
Explanation
code
3
Increment(++) / Decrement(--) Operators
Post Increment
In the prefix form the increment or decrement operation is carried
out before the rest of the expression.
Consider the following code snippet:
a b b=a
a=a+1
4
a= 4 b= 3
3
1.The value of the variable a(3) is assigned to b.
2. The variable a is incremented .
Thus the value of a and b both become 4
2
1
1
2
output
Working
Explanation
code
int a, b ;
a=3;
b=a++;
cout<<“a= “<<a<<“tb= “<<b;
Program to illustrate Increment, Decrement
operators
#include<iostream.h>
void main()
{
int a,b,c,d;
a = 0;
b = 2;
c = 4;
d = a -- + b++ - ++c;
cout<<“A= ”<<a<<“tB= ” <<b<<“tC= ”<<c“tD = "<<d;
}
A= -1 B= 3 C= 5 D= 7
The Conditional operator ( ?: )
• The conditional operator is a ternary operator having three
operands.
• It evaluates a condition and depending on whether it is true or
false it carries out one of two statements.
• Syntax:
Expression 1 ? Expression 2: Expression 3;
If Expression 1 which is a condition evaluates to true,
expression 2 is carried out otherwise expression 3 is carried
out.
Expression 2 and 3 can be any valid c++ statement
Conditional operator: illustration
• Example :
#include<iostream.h>
void main()
{int a,b;
cout<<“Enter two numbers :”<<endl;
cin>>a>>b;
cout<<“n The larger no is :”;
a>b? cout<<a : cout<<b;}
Enter two numbers :
24
22
The larger no is : 24
code
output
Working
a>b? cout<<a : cout<<b;
1 2 3
true
false
Explanation
1. Expression 1 is evaluated
2. If it returns true, expression 2 is carried out.
3. If it returns false, expression 3 is carried out.
Conditional operator: illustration
The value generated by a conditional operator can also be assigned to a variable
Thus the previous program can also be written as:
#include<iostream.h>
void main()
{int a,b, large;
cout<<“Enter two numbers :”<<endl;
cin>>a>>b;
large = a>b? a : b;
cout<<“n The larger no is :”<<large;
}
Enter two numbers :
24
22
The larger no is : 24
code
output
Working
large= a>b ? a : b;
1 2 3
true
false
Explanation
1. Expression 1 is evaluated.
2. If it returns true, large is assigned the value 24
3. If it returns false, large is assigned the value 22
4. In this case large will be assigned value 24
Conditional operator: illustration
• The conditional operator can be used to choose which variable to assign a value to:
#include<iostream.h>
void main()
{int score1, score2, Bonus_points ;
cout<<“Enter the scores :”<<endl;
cin>>score1>>score2;
Bonus_points= score1 * score2;
(score1>score2) ? score1:score2= Bonus_points;
cout<<“n New scores :”<<score1<<“#”<<score2;
}
Enter the scores :
8
9
New Scores : 8 # 72
code output
Precedence of operators
The following table enlists the precedence of various operators:
Precedence Operator Name/category Evaluation
1 a++ a-- Postfix increment and decrement Left to right
2 ++a –a
+, -
!
Prefix increment and decrement
Unary plus and minus
Logical Not
Right to left
3 *, /,% Multiplication, division and remainder Left to right
4 +, - Addition, subtraction Left to right
5 < <= Relational < and ≤ respectively
6 > >= Relational > and ≥ respectively
7 == != Relational = and ≠ respectively
8 &&, || Logical and and or respectively
9 ?:, =,
+=, -=,*=,/=,%=
Conditional operator , assignment operator
c++ shorthands
Right to left
Expressions
• Expressions are formed using any or all of the operators discussed
so far.
Expressions
arithmetic
Relational
Logical
conditional
x= r / y +p;
p= 2* a* t;
x>y
z!=p
x >y && p<=z
b>9 || v!=6
x= (a>b)? 0.9: 0.6;
x>y ? cout<<x: cout<<y;
Type Conversions
• Data type conversions take place when an expression contains
variables of different numeric data types eg. Int to float, float to
double etc.
• There are two types of conversions:
Type
Conversions
Implicit
conversion or
type promotion
Explicit
conversion or
Type Casting
Variable data type
conversion takes
place automatically
Variable data type
conversion takes
place by converting
data types explicitly
Implicit conversion or type promotion
• In an expression when we use variables of different data types ,implicit
or automatic type conversions take place. For eg:
• Here the data type of a is converted to float and then multiplied by x.
The result which is a floating point value is stored in y.
• This technique in which variables of smaller datatypes are converted to
higher data types is also known as type promotion.
int a=9;
float y, x=9.6;
y=a*x;
cout<<y; 86.4
Type conversion: the order of conversion
Data types
long double
double
float
long int
int
char
Order of conversion of variables:
Smallest to largest
Explicit Type conversion or Type Casting
Type casting is when we make a variable of one data type behave
like another. In other words we force a variable of a type to behave
like another. For example;
This will give the output as 65 which is the ASCII code of ‘A’
Here we are forcing ch which is a char variable to behave like an
integer by casting it as (int)
char ch= ‘A’;
cout<<(int)ch;
65
Type Casting
We can do type casting in two ways:
Syntax:
(data type) variable_name
Or
data type (variable_name)
For Example:
In both the statements above the output will be ‘X’ (90 is the ASCII value of ‘X’.)
When a variable of a higher data type is converted to lower data type, there is some loss of value. If
for example, we convert a float to an integer, the decimal part will be discarded.
int x=90;
cout<<char();
cout<<(char) x;
Type casting: Example Program
Showing the character representation of integers according to ASCII code
#include<iostream.h>
void main()
{ int x, y, z, d;
x=97;
y=++x;
z=++y;
d=++z +1;
cout<<“Char representation of x, y, z and d is”<<char(x)<<“ “<<char(y)<<“
“<<char(z)<<“ “<<char(d);
}
Char representation of x, y, z and d is : b c d e
Output
Program
Type casting: Example Program
Showing the ASCII code of characters on the keyboard:
#include<iostream.h>
void main()
{ char x, y ;
x=‘A’, y=‘*’;
cout<<“ASCII representation of x, y is :”<<int (x)<<“ “<<int (y);
}
ASCII representation of x, y is :65 42
Output
Program

Más contenido relacionado

La actualidad más candente

FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)Ritika Sharma
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++Nilesh Dalvi
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2MOHIT TOMAR
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++sanya6900
 
Friend function
Friend functionFriend function
Friend functionzindadili
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++Bishal Sharma
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++amber chaudary
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.pptTareq Hasan
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in CHarendra Singh
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statementnarmadhakin
 

La actualidad más candente (20)

FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++
 
Friend function
Friend functionFriend function
Friend function
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
Operators
OperatorsOperators
Operators
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 

Similar a Operators and expressions in C++

Similar a Operators and expressions in C++ (20)

C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 
Operators
OperatorsOperators
Operators
 
Programming presentation
Programming presentationProgramming presentation
Programming presentation
 
C++
C++ C++
C++
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
operators.pptx
operators.pptxoperators.pptx
operators.pptx
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
05 operators
05   operators05   operators
05 operators
 
PROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptxPROGRAMMING IN C - Operators.pptx
PROGRAMMING IN C - Operators.pptx
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Theory3
Theory3Theory3
Theory3
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 
C operators
C operators C operators
C operators
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
 
C PRESENTATION.pptx
C PRESENTATION.pptxC PRESENTATION.pptx
C PRESENTATION.pptx
 

Más de Neeru Mittal

Introduction to AI and its domains.pptx
Introduction to AI and its domains.pptxIntroduction to AI and its domains.pptx
Introduction to AI and its domains.pptxNeeru Mittal
 
Brain Storming techniques in Python
Brain Storming techniques in PythonBrain Storming techniques in Python
Brain Storming techniques in PythonNeeru Mittal
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python PandasNeeru Mittal
 
Python Tips and Tricks
Python Tips and TricksPython Tips and Tricks
Python Tips and TricksNeeru Mittal
 
Python and CSV Connectivity
Python and CSV ConnectivityPython and CSV Connectivity
Python and CSV ConnectivityNeeru Mittal
 
Working of while loop
Working of while loopWorking of while loop
Working of while loopNeeru Mittal
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++Neeru Mittal
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++Neeru Mittal
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arraysNeeru Mittal
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingNeeru Mittal
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++Neeru Mittal
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingNeeru Mittal
 
Getting started in c++
Getting started in c++Getting started in c++
Getting started in c++Neeru Mittal
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Neeru Mittal
 

Más de Neeru Mittal (17)

Machine Learning
Machine LearningMachine Learning
Machine Learning
 
Introduction to AI and its domains.pptx
Introduction to AI and its domains.pptxIntroduction to AI and its domains.pptx
Introduction to AI and its domains.pptx
 
Brain Storming techniques in Python
Brain Storming techniques in PythonBrain Storming techniques in Python
Brain Storming techniques in Python
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python Pandas
 
Python Tips and Tricks
Python Tips and TricksPython Tips and Tricks
Python Tips and Tricks
 
Python and CSV Connectivity
Python and CSV ConnectivityPython and CSV Connectivity
Python and CSV Connectivity
 
Working of while loop
Working of while loopWorking of while loop
Working of while loop
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 
Arrays
ArraysArrays
Arrays
 
Nested loops
Nested loopsNested loops
Nested loops
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Getting started in c++
Getting started in c++Getting started in c++
Getting started in c++
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 

Último

Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 

Último (20)

Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 

Operators and expressions in C++

  • 2. What are operators and expressions? Programs use data stored in variables and perform different types of operations on that data. The data on which operations are performed are known as operands and the types of the operations performed on them are known as operators. The combination of operators and expressions are known as expressions Consider the following c++ statement: z * y z and y are the operands * (multiplication is the operator z * y is an expression
  • 3. Category of Operators • Based on the number of operands there are three basic types of operators : • Unary Operators: they work on a single operand • Binary Operators: they work on two operands • Ternary Operators: they work on three operands
  • 4. Types of Operators Operators Arithmetic Unary +, -,++, - - Binary +, -, *, /, % Relational >, <, >=, <=, !=,== Logical &&, !, || Assignment = Special Conditional ? (true) :false) C++ Shorthands +=,-=.*=,/=,%=
  • 5. Arithmetic operators • These operators are used to perform simple arithmetic calculations like addition, subtraction , multiplication and division • All the arithmetic operators are binary in nature. • Only the – operator can be both unary or binary #include<iostream.h> void main() { int a, b; a=40, b=20; cout<<“n Sum of a and b :”<<a+b; cout<<“n Difference of a and b :”<<a-b; cout<<“n Product of a and b :”<<a*b; cout<<“n Quotient of a and b :”<<a/b; } Sum of a and b :60 Difference of a and b :20 Product of a and b :800 Quotient of a and b :2
  • 6. Points to note about arithmetic operators • They can be used with all data types. • The division operator (/) does integer division only. This means if we divide say 45 by 6, we will get the answer as 7 and not 7.5 as expected. This is because the / operator discards the decimal part after division. • To get the accurate answer in the above case we must write 45.0/6.0. #include<iostream.h> void main() { cout<<“Divide one :”<<45/6; cout<<“n Divide Two :”<<45.0/6.0; } Divide one : 7 Divide Two : 7.5
  • 7. • Another way to get the accurate result would be to store the numbers in float variables. #include<iostream.h> void main() { float a, b; a=45, b=6; cout<<“n a/ b = :”<<a/b; } a/b= : 7.5 Points to note about arithmetic operators
  • 8. The modulus ( % ) operator The modulus operator , represented by the percentage sign( %) gives the remainder of division. For example 2 )25 ( 12 Quotient( 25/2 ) 2 5 4 1 Remainder( 25 % 2) The modulus operator can be used only with integers. #include<iostream.h> void main() { int a, b; a=25, b=12; cout<<“n Quotient of a and b :”<<a/b; cout<<“n Remainder of division is :”<<a % b; } Quotient of a and b :12 Remainder of division is : 1
  • 9. We can only use the addition and subtraction operator with variables of char data type. 01 This is possible because data ( character or symbol) is stored in a char variable as an integer value equal to the ASCII code of the character. 02 In the statement: char ch = ‘A’; the ASCII equivalent of ‘A’ i.e. 65 is stored in ch. 03 So if we write ch=ch+1;We are actually adding 1 to 65, which becomes 66. Thus ch will now store the letter ‘B’ whose ASCII code is 66 04 Arithmetic operators and char data
  • 10. Arithmetic operators and char data #include<iostream.h> void main() { char ch=‘A’ ; cout<<“The value of character variable is:”<<ch; ch=ch+1; cout<<“n The value after adding 1 :”<<ch; } The value of character variable is: A The value after adding 1 : B
  • 11. Relational Operators • Relational operators are used to form conditions in an expression. • They are mainly used to compare variables with other variables or constants. • They are binary in nature Operator Description Expression > Greater than a>b < Less than a<b >= Greater than or equal to a>=b <= Less than or equal to a<=b == Equal to a==b != Not equal to a!=b
  • 12. Relational Operators The result of a relational expression is either true(1) or false (0). Variable value Example Expression Result a=9, b=8 a>b a>=b a==b a!=b a>2 True or 1 True or 1 False or 0 True or 1 True or 1 a=9, b=9 a>=b a==b a!=b b>9 True or 1 True or 1 False or 0 False or 0
  • 13. Using Relational Operators #include<iostream.h> void main() { int a, b; a=20, b=12; cout<<“n a>b =”<<(a>b)<<“t a!=b =“<< (a!=b); b=b+8; cout<<“n a>b =”<<(a>b)<<“t a==b =”<<(a==b); } a>b = 1 a!=b = 1 a>b = 0 a==b = 1 #include<iostream.h> void main() { int a=2, b=1,c=4,d=6,e=9,f=-6; cout<<(a>b)<<endl; cout<<(b>c)<<endl; cout<<(d<=e)<<endl; cout<<(e!=f)<<endl; cout<<(c>=a)<<endl; cout<<(a==d); } 1 0 1 1 1 0
  • 14. Logical Operators • These operators are used to combine two or more conditions. • They return true or false. • In the table x and y denote conditions Operator Type Example && Logical And Binary x && y || Logical Or Binary x || y ! Logical Not Unary !x
  • 15. Working of OR (||) operator Variable value Expression Condition 1 Result Condition 2 Result Output of expression x=15, y=7 x>y || y >6 x>y True(1) y>6 True(1) True(1) x>y || y!= 4 x>y True(1) y!=7 False(0) True(1) x<y || y==4 x<y False(0) y==7 True(1) True(1) x<y || y>7 x<y False(0) y>7 False(0) False(0)
  • 16. Working of AND (&&) operator Variable value Expression Condition 1 Result Condition 2 Result Output of expression x=15, y=7 x>y && y >6 x>y True(1) y>6 True(1) True(1) x>y && y!= 4 x>y True(1) y!=7 False(0) False(0) x<y && y==4 x<y False(0) y==7 True(1) False(0) x<y && y>7 x<y False(0) y>7 False(0) False(0)
  • 17. Working of NOT (!) operator Variable value Expression Condition Result !(Condition ) Output of expression x=15, y=4 ! (x>y ) x>y True(1) ! (True ) False(0) ! (y>7) y>7 False(0) ! (False) True(1) !(x>y || y!= 4) T || F True(1) !(True) False(0) !(x<y || y>7) F || F False(0) !(False) True(1)
  • 18. Assignment (=) Operator The Assignment operator is used to assign a value to a variable. The variable is always on the left hand side and the value on the right hand side. The value can be another variable or an expression. For eg: a=b; the value stored in variable b is assigned to a p=q+r; the sum of q and r is stored in the variable p X = 20; Variable Value In the example the variable x is assigned a value 20.
  • 19. C++ Shorthands These are operators used to perform an arithmetic function on an operand and assign the new value to the operand at the same time. Operator Description Example Equivalent to: += Addition assignment A+=B A=A+B -= Subtraction assignment A -=B A=A-B *= Multiplication assignment A*=B A=A*B /= Division assignment A/=B A=A/B %= Modulus assignment A%=B A=A%B
  • 20. Increment(++) / Decrement(--) Operators The increment(++) and decrement(--) are unary operators . The syntax is : Examples: The increment / decrement operators do not work on constants. Thus : variable ++; or ++ variable; variable --; or -- variable; a++; ++ x; p=--q; t--; 6++; //gives error as 6 is a constant x=--9; // gives error as 9 is a constant
  • 21. Increment(++) / Decrement(--) Operators The increment operator increases the value of a variable by 1 The decrement operator decreases the value of a variable by 1. Thus and a++; is the same as a=a+1; b--; is the same as b=b-1;
  • 22. Both the increment and decrement operators can be prefixed or postfixed. i.e. In the above statements both prefix and postfix forms do not make any difference in the output as these are stand alone statements. But when the pre/post increment or decrement operators are part of an expression the prefix and postfix notation does matter ++a; (prefix) is the same as a++; (postfix) Increment(++) / Decrement(--) Operators
  • 23. 3 Increment(++) / Decrement(--) Operators Pre Increment int a,b; a=3; b=++a; cout<<“a= ”<<a<<“tb= ”<<b; In the prefix form the increment or decrement operation is carried out before the rest of the expression. Consider the following code snippet: a b a=a+1 b=a 4 a= 4 b= 4 4 1.The value of the variable a is incremented first 2. The new value (4) is assigned to b. Thus the value of a and b both become 4 1 2 1 2 output Working Explanation code
  • 24. 3 Increment(++) / Decrement(--) Operators Post Increment In the prefix form the increment or decrement operation is carried out before the rest of the expression. Consider the following code snippet: a b b=a a=a+1 4 a= 4 b= 3 3 1.The value of the variable a(3) is assigned to b. 2. The variable a is incremented . Thus the value of a and b both become 4 2 1 1 2 output Working Explanation code int a, b ; a=3; b=a++; cout<<“a= “<<a<<“tb= “<<b;
  • 25. Program to illustrate Increment, Decrement operators #include<iostream.h> void main() { int a,b,c,d; a = 0; b = 2; c = 4; d = a -- + b++ - ++c; cout<<“A= ”<<a<<“tB= ” <<b<<“tC= ”<<c“tD = "<<d; } A= -1 B= 3 C= 5 D= 7
  • 26. The Conditional operator ( ?: ) • The conditional operator is a ternary operator having three operands. • It evaluates a condition and depending on whether it is true or false it carries out one of two statements. • Syntax: Expression 1 ? Expression 2: Expression 3; If Expression 1 which is a condition evaluates to true, expression 2 is carried out otherwise expression 3 is carried out. Expression 2 and 3 can be any valid c++ statement
  • 27. Conditional operator: illustration • Example : #include<iostream.h> void main() {int a,b; cout<<“Enter two numbers :”<<endl; cin>>a>>b; cout<<“n The larger no is :”; a>b? cout<<a : cout<<b;} Enter two numbers : 24 22 The larger no is : 24 code output Working a>b? cout<<a : cout<<b; 1 2 3 true false Explanation 1. Expression 1 is evaluated 2. If it returns true, expression 2 is carried out. 3. If it returns false, expression 3 is carried out.
  • 28. Conditional operator: illustration The value generated by a conditional operator can also be assigned to a variable Thus the previous program can also be written as: #include<iostream.h> void main() {int a,b, large; cout<<“Enter two numbers :”<<endl; cin>>a>>b; large = a>b? a : b; cout<<“n The larger no is :”<<large; } Enter two numbers : 24 22 The larger no is : 24 code output Working large= a>b ? a : b; 1 2 3 true false Explanation 1. Expression 1 is evaluated. 2. If it returns true, large is assigned the value 24 3. If it returns false, large is assigned the value 22 4. In this case large will be assigned value 24
  • 29. Conditional operator: illustration • The conditional operator can be used to choose which variable to assign a value to: #include<iostream.h> void main() {int score1, score2, Bonus_points ; cout<<“Enter the scores :”<<endl; cin>>score1>>score2; Bonus_points= score1 * score2; (score1>score2) ? score1:score2= Bonus_points; cout<<“n New scores :”<<score1<<“#”<<score2; } Enter the scores : 8 9 New Scores : 8 # 72 code output
  • 30. Precedence of operators The following table enlists the precedence of various operators: Precedence Operator Name/category Evaluation 1 a++ a-- Postfix increment and decrement Left to right 2 ++a –a +, - ! Prefix increment and decrement Unary plus and minus Logical Not Right to left 3 *, /,% Multiplication, division and remainder Left to right 4 +, - Addition, subtraction Left to right 5 < <= Relational < and ≤ respectively 6 > >= Relational > and ≥ respectively 7 == != Relational = and ≠ respectively 8 &&, || Logical and and or respectively 9 ?:, =, +=, -=,*=,/=,%= Conditional operator , assignment operator c++ shorthands Right to left
  • 31. Expressions • Expressions are formed using any or all of the operators discussed so far. Expressions arithmetic Relational Logical conditional x= r / y +p; p= 2* a* t; x>y z!=p x >y && p<=z b>9 || v!=6 x= (a>b)? 0.9: 0.6; x>y ? cout<<x: cout<<y;
  • 32. Type Conversions • Data type conversions take place when an expression contains variables of different numeric data types eg. Int to float, float to double etc. • There are two types of conversions: Type Conversions Implicit conversion or type promotion Explicit conversion or Type Casting Variable data type conversion takes place automatically Variable data type conversion takes place by converting data types explicitly
  • 33. Implicit conversion or type promotion • In an expression when we use variables of different data types ,implicit or automatic type conversions take place. For eg: • Here the data type of a is converted to float and then multiplied by x. The result which is a floating point value is stored in y. • This technique in which variables of smaller datatypes are converted to higher data types is also known as type promotion. int a=9; float y, x=9.6; y=a*x; cout<<y; 86.4
  • 34. Type conversion: the order of conversion Data types long double double float long int int char Order of conversion of variables: Smallest to largest
  • 35. Explicit Type conversion or Type Casting Type casting is when we make a variable of one data type behave like another. In other words we force a variable of a type to behave like another. For example; This will give the output as 65 which is the ASCII code of ‘A’ Here we are forcing ch which is a char variable to behave like an integer by casting it as (int) char ch= ‘A’; cout<<(int)ch; 65
  • 36. Type Casting We can do type casting in two ways: Syntax: (data type) variable_name Or data type (variable_name) For Example: In both the statements above the output will be ‘X’ (90 is the ASCII value of ‘X’.) When a variable of a higher data type is converted to lower data type, there is some loss of value. If for example, we convert a float to an integer, the decimal part will be discarded. int x=90; cout<<char(); cout<<(char) x;
  • 37. Type casting: Example Program Showing the character representation of integers according to ASCII code #include<iostream.h> void main() { int x, y, z, d; x=97; y=++x; z=++y; d=++z +1; cout<<“Char representation of x, y, z and d is”<<char(x)<<“ “<<char(y)<<“ “<<char(z)<<“ “<<char(d); } Char representation of x, y, z and d is : b c d e Output Program
  • 38. Type casting: Example Program Showing the ASCII code of characters on the keyboard: #include<iostream.h> void main() { char x, y ; x=‘A’, y=‘*’; cout<<“ASCII representation of x, y is :”<<int (x)<<“ “<<int (y); } ASCII representation of x, y is :65 42 Output Program