









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Chanchal Mahanthapa delivered this lecture at Chandra Shekhar Azad University of Agriculture and Technology for Programming and Computer Architecture. It includes: Expressions, Explicit, Casting, Operators, Mixed, Statement, Operand, Type, Terminology
Typology: Slides
1 / 17
This page cannot be seen from the preview
Don't miss anything!










Expressions / mixed expressions and casting (Implicitand Explicit casting), Post fix and Pre fix Operators
docsity.com
docsity.com
◦
If either operand is of type
long double
, the
other us converted to
long double
.
◦
If either operand is of type
double
, the other us
converted to
double
.
◦
If either operand is of type
float,
the other us
converted to
float
.
docsity.com
Any operand of type
char,
signed
char,
unsigned
char,
short
or
unsigned
short
is converted to type
int
, as long as type
int
can represent all values of the original
operand type. Otherwise, the operand isconverted to
unsigned
int
An enumeration type is converted to the first int,
unsigned
int,
long
or
unsigned
long
that accomodates the range
of
enum
If either operand is of type
unsigned
long
the other us converted to
unsigned
long
docsity.com
The basic idea is very simple.
With two operands of
different types the type with the lesser range ofvalues is converted to the other.
The formal rules
roughly boil down to:
◦
if the operation involves two different floating point types,the one with the lesser precision will be promoted to theother.
◦
If the operations involves an integer and a floating pointvalue, the integer will be promoted to the floating pointtype.
◦
If the operation involves mixed integer types, the type withthe more limited range will be promoted to the other.
◦
If the operation involves enumerations they will beconverted to a suitable integer type.
docsity.com
The term
conversion/implicit casting
means an automatic conversion of one typeto another.
The term
promotion
generally means a
conversion of a data value from a type withlesser range to a type with a greater range.
Explicitly conversion from one data type toanother is referred to as
cast
and the action
of explicitly converting a value is called casting
.
docsity.com
Difference between Implicit andExplicit casting
Expression
LHS Value
int1 = 7; int2 = 2;float1 = int1 / int2 + 5;
int1 = 3.8;
3
float2 = float(int1)/int2 +
float1 = 5;
docsity.com
Both the increment operator (++) and thedecrement operator(--) come in twovarieties:
Prefix and postfix.
The prefix variety is written before the variable name
(++myAge);
Variable is changed, then the expression it is in isevaluated.
The postfix variety is written after
(myAge++)
Expression the variable is in executes, then the variableis changed.
docsity.com
Post fix and Pre fixOperators(Contd.)
If
c
=
5
, then
c
is changed to
6
, then printed out
Prints out
5
(
cout
is executed before the
increment.
c
then becomes
6
docsity.com
docsity.com
docsity.com
docsity.com