You are on page 1of 4

PRN 2121g070.

Page Na
Walchond College of Enginering cDat
Assignmeot -03

Descaibe type casting9-


Type cosiog or type conuezaisn is a menod of
changing on enity framone data type to othertis
Used in Computez rogramming to ensuze Vcmables
are coizecty pacessed hy a funchion. An excmple
Ot type casting is Convezing on infegey to shig:
Ther are tueo fypes ot hpecasting:
D Implict type Casinq
i Esplicif fype casiog-

Q2 Demonshate Implicit type Conversian


When the comession auamatically_peztol@: by 1e
complley uithout ihe praq rammes inter terence it
scalled implicit typa Casting or uuidening castinq4
qenely takes place When in an exres1on Move
han one ccat hype is resent

Pragprum to demansaBe implicit type CanNersion


include <Stdio.hz
int main (
int i= 10
Ploat Z= 55
chazch 'A'

grintfi value is 7.d in';_


Deccann
Page No.
Date

=i
printF CtA Value is i ln"z;
=ch
grint6 (t i value is Ld in i
euzo O-

Out put
value s IS
7 Value is 1S.a00 aoa
i value is 65L

Q3 De mgoszate explicit fype convezsion.


This racess is clso called type castiog and it
isusez detined Here,Hhe user cao pe cast he
Tesult to maks lEofap.oticulao data type. 1ype
indicated in hzadke is he dlata ype to uhid
he tina resul! is co nver ted

Exampe
int a=2,b=83-
Ploat div;
_esplici_Conversion div=(flaat) c/

Deccan
Fuge io
Date

fzagram to demon state cxplisit kypecanvCYsjon:

E include 2Stdio.h

intmain()

nt as[0, l2=22 ,CE 30,


flaat avgi-
avg Catb-c)/3;
pxintf Avezaqe bafore conversion =1.f /n Avg)

avg=(flaah (atbtc)/3,-
printE Aerage aftsr Conyersion 1£n avg),
eturn 0j-

Outout

Average betoze conve7sion220.000000


AvecigeOftez Convezsion= 20 6666 66

o.4Dfferentiate
O.4 betimplicitand explicit type conversi an

Deccan
c'aw'marp
Page No.
Date

Tmplici Type ConvezsiolFxplicit ype Conyezsion

DTmplicit cansezshn is done) Explicitnversion isdone


altomatically pragrgmatically.

2 No daa,lossfake place dunirg 2 Data loss may or may not


COnVersion._ tak place duziog conversion:

3) No require ment of any 3 Reauire Cast operatr


Specil SyntaX. o pezfrm conversion

Example: 4 Exanple
Canversian of Smaller Aumbaz convesioo_of smalla do ta
numbr to lozper data tyø type tn latgez data p
t float int char

Deccan

You might also like