PPS Notes
PPS Notes
T-II
NTRODUCTI
ON
TOCOMPUTERS
COMPUTERSYSTEMS
―ACo
mpu
teri
sane
lec
tro
nicd
evi
cet
hats
tor
es,ma
nip
ula
tesa
ndr
etr
iev
est
hed
ata.‖Wec
an
a
lsor
efe
rco
mpu
terc
omp
ute
sthei
nfo
rma
tio
nsu
ppl
ie
dtoi
tan
dge
ner
ate
sda
ta.
ASy
ste
misagr
oupo
fse
ver
alo
bje
ctswi
thap
roc
ess
.Fo
rEx
amp
le:Ed
uca
tio
nalSy
ste
min
vol
ves
t
eac
her
,st
ude
nts(
obj
ect
s).Te
ache
rte
ache
ssu
bje
ctt
ost
ude
ntsi
.e.
,te
achi
ng(
pro
ces
s).Si
mil
arl
ya
c
omp
ute
rsy
ste
mca
nha
veo
bje
ctsa
ndp
roc
ess
.
Thefo
ll
owi
nga
ret
heo
bje
ctso
fco
mpu
terSy
ste
m
a
) Us
er(Ap
ers
onwhou
sest
hec
omp
ute
r)
b
)Ha
rdwa
re
c
) So
ftwa
re
Ha
rdwa
re: Ha
rdwa
reo
fac
omp
ute
rsy
ste
mca
nber
efe
rre
dasa
nyt
hin
gwhi
chwec
ant
ouc
han
dfe
el.
Ex
amp
le:Ke
ybo
arda
ndMo
use
.
Theha
rdwa
reo
fac
omp
ute
rsy
ste
mca
nbec
las
si
fi
eda
s
I
npu
tDe
vic
es(
I/P)
Pr
oce
ssi
ngDe
vic
es(
CPU)
Ou
tpu
tDe
vic
es(
O/P)
CPU
I
NPUT OUTPUT
ALU:I
tpe
rfo
rmst
heAr
ithme
ti
can
dLo
gic
alOp
era
tio
nss
ucha
s
+,
-,*
,/(
Ari
thme
ti
cOp
era
tor
s)
&&,|
|(Lo
gic
alOp
era
tor
s)
CU:Ev
eryOp
era
tio
nsu
cha
sst
ori
ng,c
omp
uti
nga
ndr
etr
iev
ingt
hed
atas
hou
ldb
ego
ver
nedb
ythe
c
ont
rolu
nit
.
1
MU:TheMe
mor
yun
iti
sus
edfo
rst
ori
ngt
hed
ata
.
TheMe
mor
yun
iti
scl
ass
ifi
edi
ntot
wot
ype
s.
The
yar
e 1
)Pr
ima
ryMe
mor
y
2)Se
con
dar
yMe
mor
y
Pr
ima
ryme
mor
y:Thefo
ll
owi
nga
ret
het
ype
sofme
mor
ieswhi
cha
ret
rea
teda
spr
ima
ryROM:I
t
r
epr
ese
ntsRe
adOn
lyMe
mor
ytha
tst
ore
sda
taa
ndi
nst
ruc
ti
onse
venwhe
nthec
omp
ute
rist
urn
edo
ff.
TheCo
nte
ntsi
ntheROMc
an‘
tbemo
dif
iedo
ncei
fthe
yar
ewr
itt
en.I
tisu
sedt
ost
oret
he
BI
OSi
nfo
rma
tio
n.
RAM:I
tre
pre
sen
tsRa
ndo
mAc
ces
sMe
mor
ytha
tst
ore
sda
taa
ndi
nst
ruc
ti
onswhe
nthec
omp
ute
ris
t
urn
edo
n.Thec
ont
ent
sint
heRAMc
anb
emo
difi
eda
nyn
o.o
fti
mesb
yin
str
uct
io
ns.I
tisu
sedt
o
s
tor
ethep
rogr
amsu
nde
rex
ecu
tio
n.
Ca
cheme
mor
y:I
tisu
sedt
ost
oret
hed
ataa
ndi
nst
ruc
ti
onsr
efe
rre
dbyp
roc
ess
or.
Se
con
dar
yMe
mor
y:Thefo
ll
owi
nga
ret
hed
iffe
ren
tki
ndso
fme
mor
ies
Ma
gne
ti
cSt
ora
ge:TheMa
gne
ti
cSt
ora
ged
evi
cess
tor
ein
for
mat
io
ntha
tca
nber
ead
,er
ase
dan
dre
wri
tt
ena
n
umb
ero
fti
mes
.
Ex
amp
le:Fl
opp
yDi
sks
,Ha
rdDi
sks
,Ma
gne
ti
cTa
pes
Op
tic
alSt
ora
ge:Theo
pti
cals
tor
aged
evi
cest
hatu
sel
ase
rbe
amst
ore
ada
ndwr
ites
tor
edd
ata
.
Ex
amp
le: CD(
Comp
actDi
sk)
,DVD(
Digi
talVe
rsa
til
eDi
sk)
COMPUTERSOFTWARE
So
ftwa
reo
fac
omp
ute
rsy
ste
mca
nber
efe
rre
dasa
nyt
hin
gwhi
chwec
anfe
ela
nds
ee.
Ex
amp
le:Wi
ndo
ws,
ico
ns
Co
mpu
ters
oft
war
eisd
ivi
dedi
ntot
wob
roa
dca
tego
rie
s:s
yst
ems
oft
war
ean
dap
pli
cat
io
nso
ftwa
re
.
Sys
tems
oft
war
ema
nage
sthec
omp
ute
rre
sou
rce
s.I
tpr
ovi
dest
hei
nte
rfa
ceb
etwe
ent
heha
rdwa
re
a
ndt
heu
ser
s.Ap
pli
cat
io
nso
ftwa
re,o
ntheo
the
rha
ndi
sdi
rec
tlyr
esp
ons
ibl
efo
rhe
lpi
ngu
ser
sso
lve
t
hei
rpr
obl
ems
.
Sy
ste
mSo
ftwa
re
Sy
ste
mso
ftwa
rec
ons
is
tso
fpr
ogr
amst
hatma
naget
heha
rdwa
rer
eso
urc
eso
fac
omp
ute
ran
d
p
erfo
rmr
equ
ire
din
for
mat
io
npr
oce
ssi
ngt
asks
.The
sep
rogr
amsa
red
ivi
dedi
ntot
hre
ecl
ass
es:t
he
o
per
ati
ngs
yst
em,s
yst
ems
upp
ort
,an
dsy
ste
mde
vel
opme
nt.
2
Theo
per
ati
ngs
yst
emp
rov
ide
sse
rvi
cess
ucha
sau
seri
nte
rfa
ce,fi
lea
ndd
ata
bas
eac
ces
s,a
nd
i
nte
rfa
cest
oco
mmu
nic
ati
ons
yst
emss
ucha
sIn
ter
netp
rot
oco
ls.Thep
rima
ryp
urp
oseo
fthi
sso
ftwa
re
i
stoke
ept
hes
yst
emo
per
ati
ngi
nane
ffi
ci
entma
nne
rwhi
lea
llo
win
gtheu
ser
sac
ces
stot
hes
yst
em.
Sy
ste
msu
ppo
rts
oft
war
epr
ovi
dess
yst
emu
til
it
ie
san
dot
hero
per
ati
ngs
erv
ice
s.Ex
amp
leso
fsy
ste
m
u
til
it
ie
sar
eso
rtp
rogr
amsa
ndd
iskfo
rma
tpr
ogr
ams
.Op
era
tin
gse
rvi
cesc
ons
is
tso
fpr
ogr
amst
hat
p
rov
idep
erfo
rma
nces
tat
is
ti
csfo
rtheo
per
ati
ona
lst
affa
nds
ecu
rit
ymo
nit
orst
opr
ote
ctt
hes
yst
em
a
ndd
ata
.
Thel
asts
yst
ems
oft
war
eca
tego
ry,s
yst
emd
eve
lop
men
tso
ftwa
re,i
ncl
ude
sthel
angu
aget
ran
sla
tor
s
t
hatc
onv
ertp
rogr
amsi
ntoma
chi
nel
angu
agefo
rex
ecu
tio
n,d
ebu
ggi
ngt
ool
stoe
nsu
ret
hatt
he
p
rogr
amsa
ree
rro
rfr
eea
ndc
omp
ute
r–a
ssi
st
eds
oft
war
een
gin
eer
ing(
CASE)s
yst
ems
.
Ap
pli
cat
ions
oft
war
e
Ap
pli
cat
ions
oft
war
eisb
roke
nint
otwoc
las
ses
:ge
ner
al-
pur
pos
eso
ftwa
rea
nda
ppl
ic
ati
on–s
pec
ifi
c
s
oft
war
e.Ge
ner
alp
urp
oses
oft
war
eisp
urc
has
edfr
omas
oft
war
ede
vel
ope
ran
dca
nbeu
sedfo
r
mo
ret
hano
nea
ppl
ic
ati
on.Ex
amp
leso
fge
ner
alp
urp
oses
oft
war
ein
clu
dewo
rdp
roc
ess
ors
,da
tab
ase
ma
nage
men
tsy
ste
ms,
andc
omp
ute
rai
dedd
esi
gns
yst
ems
.The
yar
ela
bel
edge
ner
alp
urp
oseb
eca
use
t
heyc
ans
olv
eav
ari
et
yofu
serc
omp
uti
ngp
rob
lems
.
Ap
pli
cat
ion–
spe
cifi
cso
ftwa
rec
anb
eus
edo
nlyfo
rit
sin
ten
dedp
urp
ose
.
Age
ner
all
edge
rsy
ste
mus
edb
yac
cou
nta
ntsa
ndama
ter
ialr
equ
ire
men
tsp
lan
nin
gsy
ste
mus
edb
ya
ma
nufa
ctu
rin
gor
gan
iza
tio
nar
eex
amp
leso
fap
pli
cat
io
n-s
pec
ifi
cso
ftwa
re.The
yca
nbeu
sedo
nlyfo
r
t
het
askfo
rwhi
cht
heywe
red
esi
gne
dthe
yca
nno
tbeu
sedfo
rot
herge
ner
ali
zedt
asks
.
Ther
ela
tio
nshi
pbe
twe
ens
yst
ema
nda
ppl
ic
ati
ons
oft
war
eiss
hownb
elo
w.I
nthi
sfi
gur
e,e
achc
irc
le
r
epr
ese
ntsa
nin
ter
fac
epo
int.
Thei
nne
rco
rei
sha
rdwa
re.Theu
seri
sre
pre
sen
tedb
ytheo
utl
aye
r.
Towo
rkwi
tht
hes
yst
em,t
het
ypi
calu
seru
sess
omefo
rmo
fap
pli
cat
io
nso
ftwa
re.Thea
ppl
ic
ati
on
s
oft
war
eint
urni
nte
rac
tswi
tht
heo
per
ati
ngs
yst
em,whi
chi
sap
arto
fthes
yst
ems
oft
war
ela
yer
.
Thes
yst
ems
oft
war
epr
ovi
dest
hed
ire
cti
nte
rac
ti
onwi
tht
heha
rdwa
re.Theo
pen
inga
ttheb
ott
omo
f
t
hefi
gur
eist
hep
athfo
ll
owe
dbyt
heu
serwhoi
nte
rac
tsd
ire
ctl
ywi
tht
heo
per
ati
ngs
yst
em
whe
nne
ces
sar
y.
3
COMPUTI
NGENVI
RONMENTS
Thewo
rd‗
comp
ute
‘isu
sedt
ore
fert
othep
roc
esso
fco
nve
rti
ngi
nfo
rma
tio
ntod
ata
.The
a
dve
nto
fse
ver
aln
ewki
ndso
fco
mpu
ter
scr
eat
edan
eedt
oha
ved
iffe
ren
tco
mpu
tin
gen
vir
onme
nts
.
Thefo
ll
owi
nga
ret
hed
iffe
ren
tki
ndso
fco
mpu
tin
gen
vir
onme
ntsa
vai
la
ble
1
. Pe
rso
nalCo
mpu
tin
gEn
vir
onme
nt
2.Ti
meSha
rin
gEn
vir
onme
nt
3.Cl
ie
nt/Se
rve
rEn
vir
onme
nt
4
.Di
st
rib
ute
dCo
mpu
tin
gEn
vir
onme
nt
Pe
rso
nalCo
mpu
tin
gEn
vir
onme
nt
I
n19
71,Ma
rci
anE.Ho
ff,wo
rki
ngfo
rINTELc
omb
ine
dtheb
asi
cel
eme
ntso
fthec
ent
ral
p
roc
ess
ingu
niti
ntot
hemi
cro
pro
ces
sor
.Ifwea
reu
sin
gap
ers
ona
lco
mpu
tert
hena
llt
hec
omp
ute
r
ha
rdwa
rec
omp
one
ntsa
ret
ie
dto
get
her
.Thi
ski
ndo
fco
mpu
tin
gisu
sedt
osa
tis
fyt
hen
eed
sofa
s
ingl
eus
er,whou
sest
hec
omp
ute
rfo
rthep
ers
ona
lta
sks
.
Ex
:Pe
rso
nalCo
mpu
ter
Ti
me-
Sha
rin
gEn
vir
onme
nt
Thec
onc
epto
fti
mes
har
ingc
omp
uti
ngi
stos
har
ethep
roc
ess
ingo
fthec
omp
ute
rba
sin
gon
t
hec
rit
eri
ati
me.I
nthi
sen
vir
onme
nta
llt
hec
omp
uti
ngmu
stb
edo
neb
ythec
ent
ralc
omp
ute
r.
4
Thec
omp
let
epr
oce
ssi
ngi
sdo
neb
ythec
ent
ralc
omp
ute
r.Thec
omp
ute
rwhi
cha
skfo
rpr
oce
ssi
nga
re
o
nlyd
umb
ter
min
als
.
Cl
ie
nt/Se
rve
rEn
vir
onme
nt
ACl
ie
nt/Se
rve
rCo
mpu
tin
gin
vol
vest
hep
roc
ess
ingb
etwe
ent
woma
chi
nes
.Ac
li
entMa
chi
nei
s
t
heo
newhi
chr
equ
est
spr
oce
ssi
ng.Se
rve
rMa
chi
nei
stheo
newhi
cho
ffe
rst
hep
roc
ess
ing.He
ncet
he
c
li
enti
sCa
pab
lee
nou
ght
odop
roc
ess
ing.A p
ort
io
nofp
roc
ess
ingi
s d
oneb
ycl
ie
nta
ndt
he
c
ore
(i
mpo
rta
nt)p
roc
ess
ingi
sdo
neb
ySe
rve
r.
Di
st
rib
ute
dCo
mpu
tin
g
Ad
ist
rib
ute
dco
mpu
tin
gen
vir
onme
ntp
rov
ide
sas
eaml
essi
nte
gra
tio
nofc
omp
uti
ngfu
nct
io
ns
b
etwe
end
iffe
ren
tse
rve
rsa
ndc
li
ent
s.Ac
li
entn
otj
ustar
equ
est
orfo
rpr
oce
ssi
ngt
hei
nfo
rma
tio
n
fr
omt
hes
erv
er.Thec
li
enta
lsoha
sthec
apa
bil
it
ytop
roc
essi
nfo
rma
tio
n.Al
lthema
chi
nes
Cl
ie
nts
/Se
rve
rss
har
ethep
roc
ess
ingt
ask.
5
Ex
amp
le:Eb
ayo
nIn
ter
net
COMPUTERLANGUAGES
Towr
iteap
rogr
am(
tel
lswha
ttod
o)fo
rac
omp
ute
r,wemu
stu
seac
omp
ute
rla
ngu
age
.
Ov
ert
hey
ear
sco
mpu
terl
angu
age
sha
vee
vol
vedfr
omma
chi
nel
angu
age
ston
atu
rall
angu
age
s.The
fo
ll
owi
ngi
sthes
umma
ryo
fco
mpu
terl
angu
age
s
1
940‘
s -
- Ma
chi
neLa
ngu
age
s
1
950‘
s -
- Sy
mbo
li
cLa
ngu
age
s
1
960‘
s -
- Hi
ghLe
velLa
ngu
age
s
Ma
chi
neLa
ngu
age
I
nthee
arl
ie
std
ayso
fco
mpu
ter
s,t
heo
nlyp
rogr
ammi
ngl
angu
age
sav
ail
abl
ewe
rema
chi
ne
l
angu
age
s.Ea
chc
omp
ute
rha
sit
sownma
chi
nel
angu
agewhi
chi
sma
deo
fst
rea
mso
f0‘
san
d1‘
s.
Thei
nst
ruc
ti
onsi
nma
chi
nel
angu
agemu
stb
eins
tre
amso
f0‘
san
d1‘
s.Thi
sisa
lsor
efe
rre
das
b
ina
ryd
igi
ts
.The
sea
res
ona
meda
sthema
chi
nec
and
ire
ctl
yun
der
sto
odt
hep
rogr
ams
Ad
van
tage
s:
1
) Hi
ghs
pee
dex
ecu
tio
n
2
)Thec
omp
ute
rca
nun
der
sto
odi
nst
ruc
ti
ons
imme
dia
tel
y
3
)Not
ran
sla
tio
nisn
eed
ed.
Di
sad
van
tage
s:
1
) Ma
chi
ned
epe
nde
nt
2
)Pr
ogr
ammi
ngi
sve
ryd
iffi
cul
t
3
)Di
ffi
cul
tto
und
ers
tan
d
4
) Di
ffi
cul
ttowr
iteb
ugfr
eep
rogr
ams
5
)Di
ffi
cul
ttoi
sol
atea
ner
ror
6
Ex
amp
leAd
dit
ono
ftwon
umb
ers
2 0010
+ 3 0011
5 0101
Sy
mbo
li
cLa
ngu
age
s(o
r)As
semb
lyLa
ngu
age
I
nthee
arl
y1950‘
sAd
mir
alGr
aceHo
ppe
r,ama
the
mat
ic
iana
ndn
ava
loffi
cer
,de
vel
ope
dthe
c
onc
epto
fas
pec
ialc
omp
ute
rpr
ogr
amt
hatwo
uldc
onv
ertp
rogr
amsi
ntoma
chi
nel
angu
age
.The
se
e
arl
ypr
ogr
ammi
ngl
angu
age
ssi
mpl
ymi
rro
redt
hema
chi
nel
angu
age
sus
ings
ymb
olso
rmn
emo
nic
sto
r
epr
ese
ntt
hev
ari
ousl
angu
agei
nst
ruc
ti
ons
.The
sel
angu
age
swe
rekn
owna
ssy
mbo
li
cla
ngu
age
s.
Be
cau
seac
omp
ute
rdo
esn
otu
nde
rst
ands
ymb
oli
cla
ngu
agei
tmu
stb
etr
ans
lat
edi
ntot
hema
chi
ne
l
angu
age
.As
pec
ialp
rogr
amc
all
eda
nAs
semb
lert
ran
sla
tess
ymb
oli
cco
dei
ntot
hema
chi
nel
angu
age
.
He
ncet
heya
rec
all
eda
sAs
semb
lyl
angu
age
.
Ad
van
tage
s:
1
) Ea
syt
oun
der
sta
nda
ndu
se
2
)Ea
syt
omo
difya
ndi
sol
ate
err
or
3
)Hi
ghe
ffi
ci
enc
y
4
) Mo
rec
ont
rolo
nha
rdwa
re
Di
sad
van
tage
s:
1
) Ma
chi
neDe
pen
den
tLa
ngu
age
2
)Re
qui
res
tra
nsl
ato
r
3
)Di
ffi
cul
ttol
ear
nan
dwr
ite
pro
gra
ms
4
) Sl
owd
eve
lop
men
tti
me
5
)Le
sse
ffi
ci
ent
Ex
amp
le:
2 PUSH2,
A
3 PUSH3,
B
+ ADDA,
B
5 PRI
NTC
7
Hi
gh-
Lev
elLa
ngu
age
s
Thes
ymb
oli
cla
ngu
age
sgr
eat
lyi
mpr
ove
dpr
ogr
ammi
nge
ffi
ci
enc
ythe
yst
il
lre
qui
red
p
rogr
amme
rst
oco
nce
ntr
ateo
ntheha
rdwa
ret
hatt
heywe
reu
sin
gwo
rki
ngwi
ths
ymb
oli
cla
ngu
age
s
wa
sal
sov
eryt
edi
ousb
eca
usee
achma
chi
nei
nst
ruc
ti
onha
dtob
ein
div
idu
all
yco
ded
.Thed
esi
ret
o
i
mpr
ovep
rogr
amme
reffi
ci
enc
yan
dtoc
han
get
hefo
cusfr
omt
hec
omp
ute
rtot
hep
rob
lemsb
ein
g
s
olv
edl
edt
othed
eve
lop
men
tofhi
gh-
lev
ell
angu
age
s.
Hi
gh-
lev
ell
angu
age
sar
epo
rta
blet
oma
nyd
iffe
ren
tco
mpu
tera
llo
win
gthep
rogr
amme
rto
c
onc
ent
rat
eont
hea
ppl
ic
ati
onp
rob
lema
tha
ndr
athe
rtha
nthei
ntr
ica
cie
soft
hec
omp
ute
r.
C As
yst
emsi
mpl
eme
nta
tio
nLa
ngu
age
C++ Cwi
tho
bje
cto
rie
nte
den
han
ceme
nts
JAVA Ob
jec
tor
ien
tedl
angu
agefo
rin
ter
neta
ndge
ner
ala
ppl
ic
ati
onsu
sin
gba
sicCs
ynt
ax
Ad
van
tage
s:
1
) Ea
syt
owr
itea
ndu
nde
rst
and
2
)Ea
syt
ois
ola
tea
ner
ror
3
)Ma
chi
nei
nde
pen
den
tla
ngu
age
4
) Ea
syt
oma
int
ain
5
)Be
tte
rre
ada
bil
it
y
6
) Lo
wDe
vel
opme
ntc
ost
7
) Ea
sie
rto
doc
ume
nt
8
) Po
rta
ble
Di
sad
van
tage
s:
1
) Ne
eds
tra
nsl
ato
r
2
)Re
qui
reshi
ghe
xec
uti
ont
ime
3
)Po
orc
ont
rolo
nha
rdwa
re
4
) Le
sse
ffi
ci
entEx
amp
le:
Cl
angu
age
#i
ncl
ude
<st
dio
.h>
v
oidma
in(
)
{
i
nta,b
, c
;
sc
anf(
"%d%d
%",
&a,
&b)
;
8
c
=a+b;
p
rin
tf(
"%d
",c
);
}
Di
ffe
ren
ceb
etwe
enMa
chi
ne,As
semb
ly,Hi
ghLe
velLa
ngu
age
s
Fe
atu
re Ma
chi
ne As
semb
ly Hi
ghLe
vel
Fo
rm 0‘
san
d1‘
s Mn
emo
nicc
ode
s No
rma
lEn
gli
sh
Ma
chi
neDe
pen
den
t De
pen
den
t De
pen
den
t I
nde
pen
den
t
Tr
ans
lat
or No
tNe
ede
d Ne
ede
d(As
semb
ler
) Ne
ede
d(Co
mpi
le
r)
Ex
ecu
tio
nTi
me Le
ss Le
ss Hi
gh
La
ngu
age
s On
lyo
ne Di
ffe
ren
tMa
nufa
ctgu
rer
s Di
ffe
ren
tLa
ngu
age
s
Na
tur
e Di
ffi
cul
t Di
ffi
cul
t Ea
sy
Me
mor
ySp
ace Le
ss Le
ss Mo
re
La
ngu
ageTr
ans
lat
ors
The
sea
ret
hep
rogr
amswhi
cha
reu
sedfo
rco
nve
rti
ngt
hep
rogr
amsi
non
ela
ngu
agei
nto
ma
chi
nel
angu
agei
nst
ruc
ti
ons
,sot
hatt
heyc
anb
eex
cut
edb
ythec
omp
ute
r.
1
) Co
mpi
le
r: I
tisap
rogr
amwhi
chi
sus
edt
oco
nve
rtt
hehi
ghl
eve
lla
ngu
age
p
rogr
amsi
ntoma
chi
nel
angu
age
2) As
semb
ler
: I
tisap
rogr
amwhi
chi
sus
edt
oco
nve
rtt
hea
sse
mbl
yle
vel
l
angu
agep
rogr
amsi
ntoma
chi
nel
angu
age
3) I
nte
rpr
ete
r:I
tisap
rogr
am,i
tta
keso
nes
tat
eme
nto
fahi
ghl
eve
lla
ngu
age
p
rogr
am,t
ran
sla
tesi
tin
toma
chi
nel
angu
agei
nst
ruc
ti
ona
ndt
heni
mme
dia
tel
y
e
xec
ute
sther
esu
lti
ngma
chi
nel
angu
agei
nst
ruc
ti
ona
nds
oon
.
Co
mpa
ris
onb
etwe
enaCo
mpi
le
ran
dIn
ter
pre
ter
COMPI
LER I
NTERPRETER
ACo
mpi
le
risu
sedt
oco
mpi
lea
nen
tir
e Ani
nte
rpr
ete
risu
sedt
otr
ans
lat
eea
chl
in
eof
p
rogr
ama
nda
nex
ecu
tab
lep
rogr
ami
s t
hep
rogr
amc
odei
mme
dia
tel
yasi
tise
nte
red
ge
ner
ate
dthr
ought
heo
bje
ctp
rogr
am
9
Thee
xec
uta
blep
rogr
ami
sst
ore
dinad
iskfo
r Thee
xec
uta
blep
rogr
ami
sge
ner
ate
dinRAM
fu
tur
eus
eort
oru
niti
nan
othe
rco
mpu
ter a
ndt
hei
nte
rpr
ete
risr
equ
ire
dfo
rea
chr
uno
f
t
hep
rogr
am
Thec
omp
il
edp
rogr
amsr
unfa
ste
r TheI
nte
rpr
ete
dpr
ogr
amsr
uns
lowe
r
Mo
sto
ftheLa
ngu
age
sus
eco
mpi
le
r Av
eryfe
wla
ngu
age
sus
ein
ter
pre
ter
s.
CREATI
NGANDRUNNI
NGPROGRAMS
Thep
roc
edu
refo
rtu
rni
ngap
rogr
amwr
itt
eni
nCi
ntoma
chi
neLa
ngu
age
.Thep
roc
essi
spr
ese
nte
din
as
tra
ight
for
war
d,l
in
earfa
shi
onb
uty
ous
hul
dre
cogn
izet
hatt
hes
est
epsa
rer
epe
ate
dma
nyt
ime
s
d
uri
ngd
eve
lop
men
ttoc
orr
ecte
rro
rsa
ndma
kei
mpr
ove
men
tst
othe
cod
e.
Thefo
ll
owi
nga
ret
hefo
urs
tep
sint
hisp
roc
ess
1
) Wr
iti
nga
ndEd
iti
ngt
hep
rogr
am
2
) Co
mpi
li
ngt
hep
rogr
am
3
) Li
nki
ngt
hep
rogr
amwi
tht
her
equ
ire
dmo
dul
es
4
) Ex
ecu
tin
gthe
pro
gra
m
1
0
TEXTEDI
TOR
COMPI
LER
Li
bra
ry LI
NKE
R
RUNNER
OUTPUT
Sl
.No
. Pha
se Na
meo
fCo
de To
ols Fi
leEx
ten
sio
n
1 Te
xtEd
ito
r So
urc
eCo
de CCo
mpi
le
rs .
C
Ed
it,
No
tep
adEt
c..
,
2 Co
mpi
le
r Ob
jec
tCo
de CCo
mpi
le
r .
OBJ
3 Li
nke
r Ex
ecu
tab
le CCo
mpi
le
r .
EXE
Co
de
4 Ru
nne
r Ex
ecu
tab
le CCo
mpi
le
r .
EXE
Co
de
Wr
iti
nga
ndEd
iti
ngPr
ogr
ams
Thes
oft
war
eus
edt
owr
itep
rogr
amsi
skn
owna
sat
exte
dit
or.At
exte
dit
orhe
lpsu
s
e
nte
r,c
han
gea
nds
tor
echa
rac
terd
ata
.On
cewewr
itet
hep
rogr
ami
nthet
exte
dit
orwes
avei
tus
ing
afi
le
names
tor
edwi
tha
nex
ten
sio
nof.
C.Thi
sfi
lei
sre
fer
reda
sso
urc
eco
defi
le
.
1
1
Co
mpi
li
ngPr
ogr
ams
Thec
odei
nas
our
cefi
les
tor
edo
nthed
iskmu
stb
etr
ans
lat
edi
ntoma
chi
nel
angu
age
.Thi
sis
t
hej
obo
fthec
omp
il
er.TheCo
mpi
le
risac
omp
ute
rpr
ogr
amt
hatt
ran
sla
test
hes
our
cec
odewr
itt
en
i
nahi
gh-
lev
ell
angu
agei
ntot
hec
orr
esp
ond
ingo
bje
ctc
odeo
fthel
ow-
lev
ell
angu
age
.Thi
s
t
ran
sla
tio
npr
oce
ssi
sca
lldc
e o
mpi
la
tio
n.Thee
nti
rehi
ghl
eve
lpr
ogr
ami
sco
nve
rte
din
tot
he
e
xec
uta
blema
chi
nec
odefi
le
.TheCo
mpi
le
rwhi
che
xec
ute
sCp
rogr
amsi
sca
lle
dasCCo
mpi
le
r.
Ex
amp
leTu
rboC,Bo
rla
ndC,GCe
tc.
,
TheCCo
mpi
le
risa
ctu
all
ytwos
epa
rat
epr
ogr
ams
:
ThePr
epr
oce
sso
r
TheTr
ans
lat
or
ThePr
epr
oce
sso
rre
adst
hes
our
cec
odea
ndp
rep
are
sitfo
rthet
ran
sla
tor
.Whi
lep
rep
ari
ngt
hec
ode
,
i
tsc
ansfo
rsp
eci
ali
nst
ruc
ti
onskn
owna
spr
epr
oce
sso
rco
mma
nds
.The
sec
omma
ndst
ellt
he
p
rep
roc
ess
ort
olo
ok fo
rsp
eci
alc
odel
ibr
ari
es
. Ther
esu
lto
fpr
epr
oce
ssi
ngi
sca
lle
dthe
t
ran
sla
tio
nun
it.
Aft
ert
hep
rep
roc
ess
orha
spr
epa
redt
hec
odefo
rco
mpi
la
tio
n,t
het
ran
sla
tord
oest
hea
ctu
al
wo
rko
fco
nve
rti
ngt
hep
rogr
ami
ntoma
chi
nel
angu
age
.Thet
ran
sla
torr
ead
sthet
ran
sla
tio
nun
ita
nd
wr
ite
sther
esu
lti
ngo
bje
ctmo
dul
etoaf
ilet
hatc
ant
henb
eco
mbi
nedwi
tho
the
rpr
eco
mpi
le
dun
itst
o
fo
rmt
hef
ina
lpr
ogr
am.Ano
bje
ctmo
dul
eist
hec
odei
nthema
chi
nel
angu
age
.
Li
nki
ngPr
ogr
ams
TheLi
nke
ras
semb
lesa
llfu
nct
io
ns,t
hep
rogr
am‘
sfu
nct
io
nsa
nds
yst
em‘
sfu
nct
io
nsi
ntoo
ne
e
xec
uta
blep
rogr
am.
Ex
ecu
tin
gPr
ogr
ams
Toe
xec
uteap
rogr
amweu
sea
nop
era
tin
gsy
ste
mco
mma
nd,s
ucha
sru
n,t
olo
adt
hep
rogr
am
i
ntop
rima
ry me
mor
yan
dex
ecu
tei
t. Ge
tti
ngt
he p
rogr
am i
nto me
mor
yist
he fu
nct
io
n
o
fan
ope
rat
ings
yst
emp
rogr
amkn
own
ast
hel
oad
er.
Itl
oca
tes
the
exe
cut
abl
epr
ogr
ama
nd
1
2
r
ead
siti
ntome
mor
y.Whe
nev
ery
thi
ngi
slo
ade
dthep
rogr
amt
ake
sco
ntr
ola
ndi
tbe
gine
xec
uti
on.
ALGORI
THM
Al
gor
ithm i
safi
ni
tes
equ
enc
eofi
nst
ruc
ti
ons
,ea
cho
fwhi
chha
sac
lea
rme
ani
nga
ndc
anb
e
p
erfo
rme
dwi
thafi
ni
tea
mou
nto
feffo
rti
nafi
ni
tel
engt
hoft
ime
.Noma
tte
rwha
tthei
npu
tva
lue
s
ma
ybe
,ana
lgo
rit
hmt
ermi
nat
esa
fte
rex
ecu
tin
gafi
ni
ten
umb
ero
fin
str
uct
io
ns.
Wer
epr
ese
nta
nal
gor
ithmu
sin
gap
seu
dol
angu
aget
hati
sac
omb
ina
tio
noft
hec
ons
tru
ctso
fa
p
rogr
ammi
ngl
angu
aget
oge
the
rwi
thi
nfo
rma
lEn
gli
shs
tat
eme
nts
.
Theo
rde
reds
eto
fin
str
uct
io
nsr
equ
ire
dtos
olv
eap
rob
lemi
skn
owna
sana
lgo
rit
hm.The
c
har
act
eri
st
ic
sofago
oda
lgo
rit
hma
re:
Pr
eci
si
on–t
hes
tep
sar
epr
eci
se
lys
tat
ed(
defi
ned
).
Un
iqu
ene
ss–r
esu
ltso
fea
chs
tepa
reu
niq
uel
yde
fin
eda
ndo
nlyd
epe
ndo
nthe
inp
uta
nd
t
her
esu
lto
fthep
rec
edi
ngs
tep
s.
Fi
ni
te
nes
s–t
hea
lgo
rit
hms
top
saft
erafi
ni
ten
umb
ero
fin
str
uct
io
nsa
ree
xec
ute
d.
I
npu
t–t
hea
lgo
rit
hmr
ece
ive
sin
put
.
Ou
tpu
t–t
hea
lgo
rit
hmp
rod
uce
sou
tpu
t.
Ge
ner
ali
ty–t
hea
lgo
rit
hma
ppl
ie
stoas
eto
fin
put
s.
Ex
amp
le
Q.Wr
iteaa
lgo
rit
hemt
ofi
ndo
utn
umb
eri
sod
dore
ven
?An
s.
s
tep1:sta
rt
s
tep2:input
numbe
r
s
tep3:rem=numbe
rmo d2
s
tep4:ifrem=0t
hen
p
rin
t"nu
mb e
re v
en"
e
lse
p
rin
t"nu
mb e
ro d
d"
e
ndi
f
s
tep5:sto
p
FLOWCHART
Fl
owc
har
tisad
iagr
amma
ticr
epr
ese
nta
tio
nofa
nal
gor
ithm.Fl
owc
har
tisv
eryhe
lpfu
linwr
iti
ng
p
rogr
ama
nde
xpl
ai
ni
ngp
rogr
amt
oot
her
s.
1
3
Sy
mbo
lsUs
edI
nFl
owc
har
t
Di
ffe
ren
tsy
mbo
lsa
reu
sedfo
rdi
ffe
ren
tst
ate
sinfl
owc
har
t,Fo
rex
amp
le:I
npu
t/Ou
tpu
tan
dde
cis
ion
ma
kin
gha
sdi
ffe
ren
tsy
mbo
ls.Thet
abl
ebe
lowd
esc
rib
esa
llt
hes
ymb
olst
hata
reu
sedi
nma
kin
g
fl
owc
har
t
Sy
mbo
l Pu
rpo
se De
scr
ipt
io
n
Us
edt
oin
dic
atet
hefl
owo
flo
gicb
yco
nne
cti
ng
Fl
owl
in
e
s
ymb
ols
.
Te
rmi
nal
(St
op/St
art
) Us
edt
ore
pre
sen
tst
arta
nde
ndo
ffl
owc
har
t.
I
npu
t/Ou
tpu
t Us
edfo
rin
puta
ndo
utp
uto
per
ati
on.
Us
edfo
rai
rthme
ti
cop
era
tio
nsa
ndd
ata
-
Pr
oce
ssi
ng
ma
nip
ula
tio
ns.
Us
edt
ore
pre
sen
ttheo
per
ati
oni
nwhi
cht
her
ear
etwo
De
si
ci
on
a
lte
rna
tiv
es,t
ruea
ndfa
lse
.
On
-pa
geCo
nne
cto
r Us
edt
ojo
ind
iffe
ren
tfl
owl
in
e
Off-
pageCo
nne
cto
r Us
edt
oco
nne
ctfl
owc
har
tpo
rti
ono
ndi
ffe
ren
tpa
ge.
Pr
ede
fin
ed Us
edt
ore
pre
sen
tagr
oupo
fst
ate
men
tsp
erfo
rmi
ng
Pr
oce
ss/Fu
nct
io
n o
nep
roc
ess
ingt
ask.
Ex
amp
leso
ffl
owc
har
tsi
npr
ogr
ammi
ng
Dr
awafl
owc
har
ttoa
ddt
won
umb
erse
nte
redb
yus
er.
1
4
Dr
awfl
owc
har
ttofi
ndt
hel
arge
sta
mon
gthr
eed
iffe
ren
tnu
mbe
rse
nte
redb
yus
er.
I
NTRODUCTI
ONTOCLANGUAGE
Ci
sage
ner
al-
pur
pos
ehi
ghl
eve
lla
ngu
aget
hatwa
sor
igi
nal
lyd
eve
lop
edb
yDe
nni
sRi
tc
hiefo
rthe
Un
ixo
per
ati
ngs
yst
em.I
twa
sfi
rsti
mpl
eme
nte
dont
heDi
git
alEq
qui
pme
ntCo
rpo
rat
io
nPDP-
11
c
omp
ute
rin1
972.
1
5
TheUn
ixo
per
ati
ngs
yst
ema
ndv
irt
ual
lya
llUn
ixa
ppl
ic
ati
onsa
rewr
itt
eni
ntheCl
angu
age
.Cha
s
n
owb
eco
meawi
del
yus
edp
rofe
ssi
ona
lla
ngu
agefo
rva
rio
usr
eas
ons
.
Ea
syt
ole
arn
St
ruc
tur
edl
angu
age
I
tpr
odu
cese
ffi
ci
ent
pro
gra
ms.
I
tca
nha
ndl
elo
w-l
eve
lac
ti
vi
ti
es
.
I
tca
nbec
omp
il
edo
nav
ari
et
yof
comp
ute
rs.
Fa
ctsa
bou
tC
Cwa
sin
ven
tedt
owr
itea
nop
era
tin
gsy
ste
mca
lle
dUNI
X.
Ci
sas
ucc
ess
oro
fBl
angu
agewhi
chwa
sin
tro
duc
eda
rou
nd1
970
Thel
angu
agewa
sfo
rma
li
zedi
n1988b
ytheAme
ric
anNa
tio
nalSt
and
ardI
nst
it
ue(
ANSI
).
By1
973UNI
XOSa
lmo
stt
ota
llywr
itt
eni
nC.
To
dayCi
sthemo
stwi
del
yus
edSy
ste
mPr
ogr
ammi
ngLa
ngu
age
.
Mo
sto
fthes
tat
eoft
hea
rts
oft
war
eha
veb
eeni
mpl
eme
nte
dus
ingC
Whyt
ous
eC?
Cwa
sin
iti
al
lyu
sedfo
rsy
ste
mde
vel
opme
ntwo
rk,i
npa
rti
cul
art
hep
rogr
amst
hatma
ke-
upt
he
o
per
ati
ngs
yst
em.Cwa
sad
ope
dasas
yst
emd
eve
lop
men
tla
ngu
ageb
eca
usei
tpr
odu
cesc
odet
hatr
uns
n
ear
lya
sfa
sta
sco
dewr
itt
eni
nas
semb
lyl
angu
age
.So
mee
xamp
leso
ftheu
seo
fCmi
ghtb
e:
Op
era
tin
gSy
ste
ms
La
ngu
age
Comp
il
ers
As
semb
ler
s
Te
xtEd
ito
rs
Pr
int
Spo
ole
rs
Ne
two
rkDr
ive
rs
Mo
der
nPr
ogr
ams
Da
taBa
ses
La
ngu
age
Int
erp
ret
ers
Ut
il
it
ie
s
CPr
ogr
amFi
le
1
6
Al
ltheCp
rogr
amsa
rewr
ite
nin
tot
extfi
le
swi
the
xte
nsi
on"
.c"fo
rex
amp
lehe
llo
.c.Yo
uca
nus
e
"
vi
"ed
ito
rtowr
itey
ourCp
rogr
ami
ntoafi
le
.
HI
STORYTOCLANGUAGE
Ci
sage
ner
al-
pur
pos
ela
ngu
agewhi
chha
sbe
enc
los
elya
sso
cia
tedwi
tht
heUNI
Xop
era
tin
gsy
ste
mfo
r
whi
chi
twa
sde
vel
ope
d-s
inc
ethes
yst
ema
ndmo
sto
fthep
rogr
amst
hatr
uni
tar
ewr
itt
eni
nC.
Ma
nyo
fthei
mpo
rta
nti
dea
sofCs
temfr
omt
hel
angu
ageBCPL,d
eve
lop
edb
yMa
rti
nRi
cha
rds
.The
i
nfl
uen
ceo
fBCPLo
nCp
roc
eed
edi
ndi
rec
tlyt
hro
ught
hel
angu
ageB,whi
chwa
swr
itt
enb
yKe
n
Tho
mps
oni
n197
0atBe
llLa
bs,fo
rthefi
rstUNI
Xsy
ste
monaDECPDP-
7
.BCPLa
ndBa
re"
typ
ele
ss"l
angu
age
swhe
rea
sCp
rov
ide
sav
ari
et
yofd
ata
typ
es.
I
n197
2 De
nni
s Ri
tc
hiea
t Be
llLa
bs wr
ite
sC a
ndi
n197
8the p
ubl
ic
ati
ono
f The C
Pr
ogr
ammi
ngLa
ngu
ageb
yKe
rni
gha
n&Ri
tc
hiec
aus
edar
evo
lut
io
nint
hec
omp
uti
ngwo
rld
.
I
n1983,t
heAme
ric
anNa
tio
nalSt
and
ard
sIn
sti
tut
e(ANSI
)es
tab
lis
hedac
ommi
tt
eet
opr
ovi
deamo
der
n,
c
omp
rehe
nsi
ved
efi
ni
ti
ono
fC.Ther
esu
lti
ngd
efi
ni
ti
on,t
heANSIs
tan
dar
d,o
r"ANSIC"
,wa
s
c
omp
let
edl
ate1
988.
BASI
CSTRUCTUREOFCPROGRAMMI
NG
1
7
1
. Do
cume
nta
tio
nse
cti
on:Thed
ocu
men
tat
io
nse
cti
onc
ons
is
tso
fas
eto
fco
mme
ntl
in
esgi
vi
ng
t
hen
ameo
fthep
rogr
am,t
hea
utho
ran
dot
herd
eta
il
s,whi
cht
hep
rogr
amme
rwo
uldl
iket
o
u
sel
ate
r.
2
. Li
nks
ect
ion
:Thel
in
kse
cti
onp
rov
ide
sin
str
uct
io
nst
othec
omp
il
ert
oli
nkfu
nct
io
nsfr
omt
he
s
yst
eml
ibr
arys
ucha
sus
in he#i
gt ncl
ude
dir
ect
ive
.
3
. De
fin
iti
ons
ect
ion
:Thed
efi
ni
ti
ons
ect
io
nde
fin
esa
lls
ymb
oli
cco
nst
ant
ssu
chu
sin
gthe
#d
efi
ned
ire
cti
ve.
4
. Gl
oba
lde
cla
rat
ions
ect
ion
:The
rea
res
omev
ari
abl
est
hata
reu
sedi
nmo
ret
hano
nefu
nct
io
n.
Su
chv
ari
abl
esa
rec
all
edgl
oba
lva
ria
ble
san
dar
ede
cla
redi
nthegl
oba
lde
cla
rat
io
nse
cti
on
t
hati
sou
tsi
deo
fal
lthef
unc
ti
ons
.Thi
sse
cti
ona
lsod
ecl
are
sal
l heu
t ser
-
d
efi
ned
fun
cti
ons
.
5
. ma
in(
)fu
nct
ions
ect
ion
:Ev
eryCp
rogr
ammu
stha
veo
nema
infu
nct
io
nse
cti
on.Thi
sse
cti
on
c
ont
ain
stwop
art
s;d
ecl
ara
tio
npa
rta
nde
xec
uta
ble
par
t
1
. De
cla
rat
ionp
art
: Thed
ecl
ara
tio
npa
rtd
ecl
are
sal
lthe v
ari
abl
esu
sedi
nthe
e
xec
uta
ble
par
t.
2.Ex
ecu
tab
lep
art
:The
rei
satl
eas
ton
est
ate
men
tint
hee
xec
uta
blep
art
.The
set
wo
p
art
s mu
sta
ppe
arb
etwe
ent
he o
pen
inga
ndc
los
ingb
rac
es. The p
rogr
am
e
xec
uti
onb
egi
nsa
ttheo
pen
ingb
rac
ean
den
dsa
tthec
los
ingb
rac
e.Thec
los
ingb
rac
e
o
fthema
infu
nct
io
nist
hel
ogi
cale
ndo
fthep
rogr
am.Al
lst
ate
men
tsi
nthe
d
ecl
ara
tio
nan
dex
ecu
tab
lep
arte
ndwi
tha
semi
col
on.
6
. Su
bpr
ogr
ams
ect
ion
:Ift
hep
rogr
a samu
mi lti
-fu
nct
io
npr
ogr
amt
hent
hes
ubp
rogr
ams
ect
io
n
c
ont
ain
sal
lt u
hese
r-d
efi
nedfu
nct
io
nst
hata
rec
all
edi
nthema
in(
)fu
nct
io
n.Us
er-
defi
ned
fu
nct
io
nsa
rege
ner
all
ypl
ace
dimme
dia
tel
yaft
ert
hema
in(
)fu
nct
io
n,a
ltho
ught
heyma
y
a
ppe
ari
nan
yor
der
.
PROCESSOFCOMPI
LINGANDRUNNI
NGCPROGRAM
Wewi
llb
rie
flyhi
ghl
ightke
yfe
atu
reso
ftheCCo
mpi
la
tio
nmo
delhe
re.
1
8
TheCCo
mpi
la
tio
nMo
del
ThePr
epr
oce
sso
r
ThePr
epr
oce
sso
rac
cep
tss
our
cec
odea
sin
puta
ndi
sre
spo
nsi
blefo
r
r
emo
vin
gco
mme
nts
I
nte
rpr
eti
ngs
pec
ialp
rep
roc
ess
ord
ire
cti
vesd
eno
tedb
y#.
Fo
rex
amp
le
#i
ncl
ude-
-in
clu
desc
ont
ent
sofan
ame
dfi
le
.Fi
le
sus
ual
lyc
all
edhe
ade
rfi
le
s.e
.g
o #i
ncl
ude<
mat
h.h>-
-st
and
ardl
ibr
aryma
ths
fil
e.
o #i
ncl
ude<
std
io.
h>-
-st
and
ardl
ibr
aryI
/Ofi
le
#d
efi
ne-
-de
fin
esas
ymb
oli
cna
meo
rco
nst
ant
.Ma
cro
sub
sti
tut
io
n.
o #d
efi
neMAX_ARRAY_SI
ZE1
00
CCo
mpi
le
r
TheCc
omp
il
ert
ran
sla
tess
our
cet
oas
semb
lyc
ode
.Thes
our
cec
odei
sre
cei
vedfr
omt
hep
rep
roc
ess
or.
As
semb
ler
Thea
sse
mbl
erc
rea
teso
bje
ctc
ode
.OnaUNI
Xsy
ste
myo
uma
yse
efi
le
swi
tha.
osu
ffi
x
(
.OBJo
nMSDOS)t
oin
dic
ateo
bje
ctc
odefi
le
s.
Li
nkEd
ito
r
I
fas
our
cefi
ler
efe
ren
cesl
ibr
aryfu
nct
io
nso
rfu
nct
io
nsd
efi
nedi
not
hers
our
cefi
le
sthel
ink
e
dit
orc
omb
ine
sthe
sefu
nct
io
ns(
wit
hma
in(
))t
ocr
eat
eane
xec
uta
blefi
le
.
1
9
CTOKENS
Ct
oke
nsa
ret
heb
asi
cbu
il
di
ngsb
loc
ksi
nCl
angu
agewhi
cha
rec
ons
tru
cte
dto
get
hert
owr
iteaC
p
rogr
am.
Ea
cha
nde
ver
ysma
lle
sti
ndi
vi
dua
lun
iti
naCp
rogr
ami
skn
owna
sCt
oke
ns.C
t
oke
nsa
reo
fsi
xty
pes
.The
yar
e
Ke
ywo
rds (
eg:i
nt,
whi
le
),
I
den
tifi
ers (
eg:ma
in,
tot
al)
,
Co
nst
ant
s (
eg:1
0,20)
,
St
rin
gs (
eg:―t
ota
l‖,―h
ell
o‖
),
Sp
eci
als
ymb
ols(
eg:(
),{
}),
Op
era
tor
s (
eg:+,/,
-,*
)
CKEYWORDS
Cke
ywo
rdsa
ret
hewo
rdst
hatc
onv
eyas
pec
ialme
ani
ngt
othecc
omp
il
er.Theke
ywo
rds
c
ann
otb
eus
eda
sva
ria
blen
ame
s.
Thel
is
tofCke
ywo
rdsi
sgi
venb
elo
w:
a
uto b
rea
k c
ase c
har c
ons
t
c
ont
inu
e d
efa
ult d
o d
oub
le e
lse
e
num e
xte
rn fl
oat fo
r go
to
i
f i
nt l
ong r
egi
st
er r
etu
rn
s
hor
t s
ign
ed s
ize
of s
tat
ic s
tru
ct
s
wit
ch t
ype
def u
nio
n u
nsi
gne
d v
oid
v
ola
til
e whi
le
20
CI
DENTI
FIERS
I
den
tifi
ersa
reu
seda
sthege
ner
alt
ermi
nol
ogyfo
rthen
ame
sofv
ari
abl
es,fu
nct
io
nsa
nda
rra
ys.
The
sea
reu
serd
efi
nedn
ame
sco
nsi
st
ingo
far
bit
rar
il
ylo
ngs
equ
enc
eofl
ett
ersa
ndd
igi
tswi
the
it
her
al
ett
ero
rtheu
nde
rsc
ore
(_)a
safi
rstc
har
act
er.
The
rea
rec
ert
ainr
ule
stha
tsho
uldb
efo
ll
owe
dwhi
len
ami
ngci
den
tifi
ers
:
The
ymu
stb
egi
nwi
thal
ett
ero
run
der
sco
re(
_).
The
ymu
stc
ons
is
tofo
nlyl
ett
ers
,di
git
s,o
run
der
sco
re.Noo
the
rsp
eci
alc
har
act
eri
sal
lo
wed
.It
s
hou
ldn
otb
eake
ywo
rd.
I
tmu
stn
otc
ont
ainwhi
te
spa
ce.
I
tsho
uldb
eupt
o31c
har
act
ersl
onga
son
lyfi
rst31c
har
act
ersa
res
ign
ifi
can
t.
So
mee
xamp
leso
fci
den
tifi
ers
:
Na
me Re
mar
k
_A9 Va
li
d
Te
mp.
var I
nva
li
dasi
tco
nta
inss
pec
ialc
har
act
ero
the
rtha
ntheu
nde
rsc
ore
v
oid I
nva
li
dasi
tisake
ywo
rd
CCONSTANTS
ACc
ons
tan
tre
fer
stot
hed
atai
te
mst
hatd
ono
tcha
nget
hei
rva
lued
uri
ngt
hep
rogr
ame
xec
uti
on.
Se
ver
alt
ype
sofCc
ons
tan
tst
hata
rea
llo
wedi
nCa
re:
I
nte
gerCo
nst
ant
s
I
nte
gerc
ons
tan
tsa
rewho
len
umb
erswi
tho
uta
nyfr
act
io
nalp
art
.Itmu
stha
vea
tle
asto
ned
igi
tan
d
ma
yco
nta
ine
it
her+o
r–s
ign
.An
umb
erwi
thn
osi
gni
sas
sume
dtob
epo
sit
ive
.
The
rea
ret
hre
ety
peso
fin
tege
rco
nst
ant
s:
De
cima
lIn
tege
rCo
nst
ant
s
I
nte
gerc
ons
tan
tsc
ons
is
ti
ngo
fas
eto
fdi
git
s,0t
hro
ugh9,p
rec
ede
dbya
nop
tio
nal–o
r+s
ign
.
Ex
amp
leo
fva
li
dde
cima
lin
tege
rco
nst
ant
s
34
1,-
341
,0,
897
2
Oc
talI
nte
gerCo
nst
ant
s
I
nte
gerc
ons
tan
tsc
ons
is
ti
ngo
fse
que
nceo
fdi
git
sfr
omt
hes
et0t
hro
ugh7s
tar
tin
gwi
th0i
ssa
idt
o
b
eoc
tali
nte
gerc
ons
tan
ts.
21
Ex
amp
leo
fva
li
doc
tali
nte
gerc
ons
tan
ts01
0,
04
24,0,
054
0
He
xad
eci
malI
nte
gerCo
nst
ant
s
He
xad
eci
mali
nte
gerc
ons
tan
tsa
rei
nte
gerc
ons
tan
tsha
vin
gse
que
nceo
fdi
git
spr
ece
dedb
y0xo
r0X.
The
yma
yal
soi
ncl
udea
lpha
bet
sfr
omAt
oFr
epr
ese
nti
ngn
umb
ers1
0to1
5.
Ex
amp
leo
fva
li
dhe
xad
eci
mali
nte
gerc
ons
tan
ts0x
D,
0X8d
,0X,0x
bD
I
tsho
uldb
eno
tedt
hat
,oc
tala
ndhe
xad
eci
mali
nte
gerc
ons
tan
tsa
rer
are
lyu
sedi
npr
ogr
ammi
ng.
Re
alCo
nst
ant
s
Then
umb
ersha
vin
gfr
act
io
nalp
art
sar
eca
lle
dre
alo
rfl
oat
ingp
oin
tco
nst
ant
s.The
sema
ybe
r
epr
ese
nte
dino
neo
fthet
wofo
rmsc
all
edfr
act
io
nalfo
rmo
rthee
xpo
nen
tfo
rma
ndma
yal
so
ha
vee
it
her+o
r–s
ignp
rec
edi
ngi
t.
Ex
amp
leo
fva
li
dre
alc
ons
tan
tsi
nfr
act
io
nalfo
rmo
rde
cima
lno
tat
io
n0.
05,
-
0.905,562.
05,0.
015
Re
pre
sen
tin
gar
ealc
ons
tan
tine
xpo
nen
tfo
rm
Thege
ner
alfo
rma
tinwhi
char
ealn
umb
erma
yber
epr
ese
nte
dine
xpo
nen
tia
lors
cie
nti
fi
cfo
rmi
s
ma
nti
ssaee
xpo
nen
t
Thema
nti
ss
amu
stb
eei
the
rani
nte
gero
rar
ealn
umb
ere
xpr
ess
edi
nde
cima
lno
tat
io
n.
Thel
ett
eres
epa
rat
ingt
hema
nti
ss
aan
dthee
xpo
nen
tca
nal
sob
ewr
itt
eni
nup
per
cas
ei.
e.EAn
d,
t
hee
xpo
nen
tmu
stb
eani
nte
ger
.
Ex
amp
leso
fva
li
dre
alc
ons
tan
tsi
nex
pon
entfo
rma
re:
252E85,0.
15E-
10,
-3e
+8
Cha
rac
terCo
nst
ant
s
Ac
har
act
erc
ons
tan
tco
nta
inso
nes
ingl
echa
rac
tere
ncl
ose
dwi
thi
nsi
ngl
equ
ote
s.
Ex
amp
leso
fva
li
dcha
rac
terc
ons
tan
ts
‗
a‘,‗
Z‘,
‗5‘
I
tsho
uldb
eno
tedt
hatc
har
act
erc
ons
tan
tsha
ven
ume
ric
alv
alu
eskn
owna
sASCI
Iva
lue
s,fo
rex
amp
le,
t
hev
alu
eof‗
A‘i
s65whi
chi
sit
sASCI
Iva
lue
.
Es
cap
eCha
rac
ter
s/Es
cap
eSe
que
nce
s
22
Ca
llo
wsu
stoha
vec
ert
ainn
ongr
aphi
ccha
rac
ter
sinc
har
act
erc
ons
tan
ts.No
ngr
aphi
ccha
rac
ter
s
a
ret
hos
echa
rac
ter
stha
tca
nno
tbet
ype
ddi
rec
tlyfr
omke
ybo
ard
,fo
rex
amp
le,t
abs
,ca
rri
age
r
etu
rn,e
tc.
The
sen
ongr
aphi
ccha
rac
ter
sca
nber
epr
ese
nte
dbyu
sin
ges
cap
ese
que
nce
sre
pre
sen
tedb
yab
acks
las
h()
fo
ll
owe
dbyo
neo
rmo
rec
har
act
ers
.
NOTE:Ane
sca
pes
equ
enc
eco
nsu
meso
nlyo
neb
yteo
fsp
acea
sitr
epr
ese
ntsas
ingl
echa
rac
ter
.
Es
cap
eSe
que
nce De
scr
ipt
ion
a Au
dib
lea
ler
t(b
ell
)
b Ba
cks
pac
e
f Fo
rmfe
ed
n Ne
wli
ne
r Ca
rri
ager
etu
rn
t Ho
riz
ont
alt
ab
v Ve
rti
calt
ab
\ Ba
cks
las
h
― Do
ubl
equ
ota
tio
nma
rk
‗ Si
ngl
equ
ota
tio
nma
rk
? Qu
est
io
nma
rk
Nu
ll
STRI
NGCONSTANTS
St
rin
gco
nst
ant
sar
ese
que
nceo
fcha
rac
ter
sen
clo
sedwi
thi
ndo
ubl
equ
ote
s.Fo
rex
amp
le,
―he
ll
o‖
―a
bc‖
―he
ll
o91
1‖
Ev
ery
sti
ngc
ons
tan
tis
aut
oma
tic
all
yte
rmi
nat
edwi
tha
spe
cia
lcha
rac
ter
„‟c
all
edt
hen
ullc
har
act
er
whi
chr
epr
ese
ntst
hee
ndo
fthe
str
ing.
Fo
rex
amp
le,―he
ll
o‖wi
llr
epr
ese
nt―hel
lo‖i
nthe
memo
ry.
Thu
s,t
hes
izeo
fthes
tri
ngi
sthet
ota
lnu
mbe
rofc
har
act
ersp
luso
nefo
rthen
ullc
har
act
er.
23
Sp
eci
alSy
mbo
ls
Thefo
ll
owi
ngs
pec
ials
ymb
olsa
reu
sedi
nCha
vin
gso
mes
pec
ialme
ani
nga
ndt
hus
,ca
nno
tbeu
sedfo
r
s
omeo
the
rpu
rpo
se.
[
](){
},;:*…=#
Br
ace
s{}
:The
seo
pen
inga
nde
ndi
ngc
url
ybr
ace
sma
rkst
hes
tar
tan
den
dofab
loc
kofc
ode
c
ont
ain
ingmo
ret
hano
nee
xec
uta
bles
tat
eme
nt.
Pa
ren
the
ses
()
:The
ses
pec
ials
ymb
olsa
reu
sedt
oin
dic
atefu
nct
io
nca
llsa
ndfu
nct
io
npa
rame
ter
s.
Br
acke
ts[
]:Op
eni
nga
ndc
los
ingb
rac
ket
sar
eus
eda
sar
raye
leme
ntr
efe
ren
ce.The
sei
ndi
cat
esi
ngl
e
a
ndmu
lti
di
men
sio
nals
ubs
cri
pts
.
VARI
ABLES
Avari
abl
eisnothi
ngbu tanamegiv
entoas t
orageare
athato
urp ro
gramsca nmani
pul
ate
.Each
v
ari
abl
einCha saspe
cifict
ype,whi
chdet
ermin
esthesi
zeandl
ayou
toft hevari
abl
e'
smemory;t
he
r
angeofval
uestha
tcanb est
oredwi
thi
nthatmemory
;a n
dthese
tofo p
erati
onstha
tcanbeappl
ie
d
t
othevar
iab
le.
Then a
meo favari
ableca
nb eco
mp o
sedoflet
ter
s,di
gits
,a n
dtheu n
ders
cor
echara
cter.I
tmust
begi
nwitheit
herale
ttero
ra nu
nders
core
.Upperandl
owerc
asele
tte
rsaredi
st
inc
tbec
auseCisca
se
-sen
sit
ive
.Basedonthebasi
ctype
sexpla
ine
dintheprev
iou
schapte
r,therewi
llbethefol
lowi
ng
basi
cvari
abl
etype
s−
Ty
pe De
scr
ipt
ion
c
har Ty
pic
all
yas
ingl
eoc
tet
(on
eby
te)
.Thi
sisa
nin
tege
rty
pe.
i
nt Themo
stn
atu
rals
izeo
fin
tege
rfo
rthema
chi
ne.
fl
oat As
ingl
e-p
rec
isi
onfl
oat
ingp
oin
tva
lue
.
d
oub
le Ad
oub
le-
pre
cis
ionfl
oat
ingp
oin
tva
lue
.
v
oid Re
pre
sen
tst
hea
bse
nceo
fty
pe.
24
Cprogra
mmingla
ngua
geals
oa l
lo
wsdefi
ni
ngv
ari
ouso
the
rty
peso
fva
ria
ble
sli
keEn
ume
rat
io
n,
Po
int
er,Arr
ay,Str
uct
ure
,Unio
n,et
c.
Va
ria
bleDe
fin
iti
oni
nC
Avari
abl
ede
fin
iti
onte
llsthec
ompi
le
rwher
eandhowmuchs
tor
aget
oc r
eat
efortheva
ria
ble.A
va
ria
bled
efi
ni
ti
onspe
cifi
esadat
atypea
ndco
nta
insal
is
tofon
eormorevar
iab
leso
fthatty
peas
fo
llo
ws−
t
ypev
ari
abl
e_l
is
t;
He
re,t
ypemu
stb
eav
ali
dCd
atat
ypei
ncl
udi
ngc
har
,w_c
har
,in
t,fl
oat
,do
ubl
e,b
ool
,ora
nyu
ser
-
defi
nedo
bje
ct;a
ndv
ari
abl
e_l
is
tma
yco
nsi
sto
fon
eormo
rei
den
tifi
ern
ame
sse
par
ate
dbyc
omma
s.
So
mev
ali
dde
cla
rat
io
nsa
res
hownhe
re−
i
n ti ,j,k;
charc,ch;
floatf,
sala
ry;dou
ble
d
T;heli
nein
ti,j,k;d
ecl
are
san
dde
fin
est
hev
ari
abl
esi
,j,a
ndk;whi
chi
nst
ruc
tthec
omp
il
ert
o
c
rea
tev
ari
abl
esn
ame
di,ja
ndko
fty
pei
nt.
Var
iab
lescanb
eini
ti
al
iz
ed(
ass
igneda
nini
ti
alval
ue)i
nthe
ird
ecl
ara
tio
n.Thei
ni
ti
al
iz
erc
ons
is
tso
f
ane
qualsi
gnfol
lo
wedbyac
onsta
ntexpr
ess
iona
sfo l
lo
ws−
t
ypev
ari
abl
e_n
ame=v
alu
e;
So
mee
xamp
lesa
re−
e
xter
nintd=3,f=
5; / /dec
lar
ati
ono
fda ndf.
i
ntd=3,f =5; //defi
ni
ti
onandi
ni
ti
ali
zin
gda ndf.
b
ytez=22; //defi
ni
ti
onandi
ni
ti
ali
zesz
.
c
harx='x'
; //thevari
abl
exhastheval
ue'
x'
.
Fo
rdefi
ni
ti
onwi
tho
uta
nin
iti
al
iz
er:v
ari
abl
eswithst
ati
cst
ora
ged u
rat
io
na r
eimpl
ic
it
lyin
iti
al
iz
ed
wi
thNULL(a
llb
yte
sha
vet
heval
ue0)
;thei
nit
ialv
alu
eofal
lothe
rvari
abl
esareu
nde
fin
ed.
25
Va
ria
bleDe
cla
rat
io
ninC
Avari
abl
edecla
rati
onp ro
vid
esassur
ancetothecompil
erthatt
hereexi
stsavari
abl
ewiththegive
n
t
ypeandn a
mes ot ha
tt hec o
mpil
erc anp r
ocee
dfo rfurthe
rc o
mp i
la
tio
nwi t
houtreq
uiri
ngthe
c
omple
tedeta
ilaboutthevari
able
.Av aria
b l
edefin
iti
onhasit
smeanin
ga ttheti
meo fco
mp i
la
tio
n
o
nly
;t heco
mp i
lernee
d sact
ualvari
abl
ed efi
nit
io
na ttheti
meo fli
nki
ngt hepro
gram.Av ari
abl
e
d
ecl
arati
oni
susefulwhenmu l
tip
lefil
esareused.
OPERATORSANDEXPRESSI
ONS
Cl
angu
ageo
ffe
rsma
nyt
ype
sofo
per
ato
rs.The
yar
e,
1
. Ar
ithme
ti
cop
era
tor
s
2.As
si
gnme
nto
per
ato
rs
3.Re
lat
io
nal
ope
rat
ors
4
.Lo
gic
alo
per
ato
rs
5.Bi
twi
se
ope
rat
ors
6
.Co
ndi
ti
ona
lop
era
tor
s(t
ern
ary
ope
rat
ors
)
7
.In
cre
men
t/d
ecr
eme
nto
per
ato
rs
8
.Sp
eci
al
ope
rat
ors
S.
no Ty
peso
fOp
era
tor
s De
scr
ipt
ion
Thes
eareusedt
operfo
rm mat
hemati
calca
lcu
lat
io
ns
li
ke ad
dit
io
n,subt
ract
io
n, mult
ipl
ic
ati
on,d i
vi
si
on
1 Ar
ithme
tic
_op
era
tor
s and
modu
lus
The
seareu
sedt
oas
si
gnt
hev
alu
esfo
rthev
ari
abl
esi
n
2 As
sign
men
t_o
per
ato
rs Cprogr
ams.
Thes
eopera
tor
sar
eus
edt
oco
mpa
ret
hev
alu
eoft
wo
3 Re
lat
ion
alo
per
ato
rs var
iab
les
.
4 Lo
gic
alo
per
ato
rs
The
se o
per
ato
rs a
reu
sed t
ope
rfo
rm l
ogi
cal
26
o
per
ati
onso
nthegi
vent
wov
ari
abl
es.
The
seope
rato
rsareu
sedt
ope
rfo
rmb
ito
per
ati
onso
n
5 Bi
twi
seo
per
ato
rs gi
vent
wov a
ria
ble
s.
Cond
iti
ona
l Con
dit
ion
alop
erato
rsre
tur
nonev
alu
eifcond
iti
oni
str
ue
6 (t
erna
ry)o
per
ato
rs an
dr e
turn
sanot
herva
luei
sco
ndi
ti
onisfa
lse
.
I
ncr
emen
t/d
ecr
eme
nto
p Thes
eope
r a
tor
sareus
edt
oeit
heri
ncr
eas
eor
7 e
rato
rs dec
rea
setheval
ueoft
heva
ria
bleb
yone.
8 Sp
eci
alo
per
ato
rs &,*
,si
zeo
f()a
ndt
ern
aryo
per
ato
rs.
ARI
THMETI
COPERATORSI
NC
CAri
thmeti
cop
era
tor
sareu
sedt
oper
for
mma the
mat
ic
alc
alc
ula
tio
nsl
ikea
ddi
ti
on,s
ubt
rac
ti
on,
mu
lti
pli
cat
io
n,di
vi
si
onan
dmodul
usi
nCprogr
ams.
Ar
ithmet
ic
S.
no Op
erato
rs Op
era
tio
n Ex
amp
le
1 + Ad
dit
io
n A+B
2 – Su
btr
act
io
n A-
B
3 * mu
lti
pl
ic
ati
on A*
B
4 / Di
vi
si
on A/B
5 % Mo
dul
us A%B
EXAMPLEPROGRAMFORCARI
THMETI
COPERATORS
I
nthi
se
xample
progr
am,twov
alu
es―40‖a
nd―20‖areu
sed
top
erfor
mari
thmeti
co
pera
ti
ons
s
uchas
addi
ti
on,s
ubtr
act
ion
,mult
ipl
ic
ati
on,
div
isi
on,
modul
usan
dout
put
isd
isp
laye
dfore
ach
o
perat
io
n.
27
#i
ncl
ude<
std
io.
h>i
nt
ma
in(
)
i
nta
=40,
b=20,a
dd,
sub
,mu
l,d
iv,
mod
;
a
dd=
a+b
;
s
ub=a
-b;
mu
l=a
*b;
d
iv=a
/b;
mo
d=a
%b;
p
rin
tf(
"Ad
dit
io
nofa
,bi
s:%d
\n"
,ad
d);
p
rin
tf(
"Su
btr
act
io
nofa
,bi
s:%d
\n"
,su
b);
p
rin
tf(
"Mu
lti
pl
ic
ati
ono
fa,bi
s:%d
\n"
,mu
l);
p
rin
tf(
"Di
vi
si
ono
fa,bi
s:%d
\n"
,di
v)
;
p
rin
tf(
"Mo
dul
uso
fa,bi
s:%d
\n"
,mo
d);
OUTPUT:
Addi
ti
onofa ,bis:60
Subt
ract
ionofa,bis:20
Mult
ipl
ic
atio
nofa ,bi
s:800
Div
isi
onofa,bis:2Mo d
ulu
s
ofa,bis:0
ASSI
GNMENTOPERATORSI
NC
InCprograms
,val
uesfort
heva
ria
ble
sareass
ign
edus
inga
ssi
gnme
ntope
rat
ors
.
Forex
amp l
e,ift
hevalu
e―10‖i
stobeas
sign
edfort
hevar
iab
le―sum‖
,itc
anbea
ssi
gne
das
―su
m=10;‖
Ot
hera
ssi
gnme
nto
per
ato
rsi
nCl
angu
agea
regi
venb
elo
w.
28
Op
era
tor
s Ex
amp
le Ex
pla
nat
ion
Si
mple
a
ssi
gnmen
t 1
0isas
si
gnedt
o
oper
ato
r = s
um=1
0 v
ari
abl
esum
s
um+= Thisi
ssa
mea
s
+= 1
0 sum=sum+1
0
Thisi
ssa
mea
s
-
= s
um-
=10 sum=sum–1
0
s
um*
= Thisi
ssa
meas
*
= 1
0 sum=sum*1
0
Thisi
ssa
mea
s
/+ s
um/=1
0 sum=sum/1
0
Thisi
ssa
mea
s
s
um%= sum=sum%1
0
%= 1
0
Thisi
ssa
mea
s
sum=sum&1
0
&= s
um&=
10
Compou
nd
as
sign
ment s
um^
= Thisi
ssa
meas
op
erat
ors ^
= 1
0 sum=sum^1
0
EXAMPLEPROGRAMFORCASSI
GNMENTOPERATORS:
I
nthi
sprogram,val
uesfro
m0–9a resu
mmedupandt
ota
l―4 5‖isd
isp
lay
eda
sout
put
.As s
ign
ment
o
pera
tor
ss u
chas―=
‖and―+=‖a
reu
sedint
hisp
rogr
amtoass
igntheva
luesa
ndt
osu
mu ptheval
ues
.
29
#i
ncl
ude<
std
io.
h>
i
ntma
in(
)
i
ntTo
tal
=0,
i;
fo
r(i
=0;
i<1
0;i
++)
To
tal
+=i
;//Thi
siss
amea
sTo
tal=To
ata
l+i
p
rin
tf(
"To
tal=%d
",To
tal
);
OUTPUT:
To
tal=4
5
RELATI
ONALOPERATORSI
NC
Rel
ati
ona
loper
ato
rsa
reus
edt
ofi
ndt
her
ela
tio
nbe
twe
ent
wov
ari
abl
es.i
.e.t
oco
mpa
ret
hev
alu
eso
f
twova
ria
ble
sinaCpr
ogr
am.
S.
no Op
era
tor
s Ex
amp
le De
scr
ipt
ion
xi
sgr
eat
ert
han
1 > x>y y
2 < x<y xi
sle
sst
hany
xisgre
atert
han
3 >
= x>
=y oreq
ualtoy
xisl
esst
hano
r
4 <
= x<
=y eq
ualt
oy
30
5 =
= x=
=y xi
seq
ualt
oy
xi
sno
teq
ualt
o
6 !
= x!
=y y
EXAMPLEPROGRAMFORRELATI
ONALOPERATORSI
NC
I
nthispr
ogr am,r e
lat
io
nalope
rato
r(==)i
susedtoc
ompare2val
ueswhet
herthe
ya reequ
alar
e
no
t.
I
fb o
thval
u esareequal
,outp
utisdi
spl
ayedas‖val
uesa
reequal
‖.El
se,out
puti
sd i
spl
aye
das
―v a
lue
sar enotequal
‖.
Not
e:doubleequalsi
gn(==)s
houl
db eu
sedtocompa
re2value
s.Wes ho
uldnots
ingl
eequal
si
gn(
=).
#i
ncl
ude<
std
io.h>
i
ntma
in(
)
i
ntm=
40,
n=20;
i
f(m=
=n)
p
rin
tf(
"ma
ndna
ree
qua
l")
;
e
lse
p
rin
tf(
"ma
ndna
ren
ote
qua
l")
;
OUTPUT:
ma
ndna
ren
ote
qua
l
31
LOGI
CALOPERATORSI
NC
The
seoper
ato
rsareuse
dtoper
for
ml o
gic
aloper
ati
onso
nt hegi
vene
xpre
ssi
ons
.
The
reare3logi
calo
perat
orsi
nClan
guage.Theyar
e,logic
alAND(&&)
,logi
calOR(
||
)an
dlo
gic
al
NOT(!
).
S.
no Op
era
tor
s Na
me Ex
amp
le De
scr
ipt
ion
I
tretur
nstr
ue
whenbot
h
l
ogi
cal co
ndit
io
ns
1 && AND (
x>5)
&&(
y<5) ar
etrue
I
tretur
n str
ue
whenat-le
ast
on
eoft he
lo
gic
al co
ndit
io
ni s
2 |
| OR (
x>=
10)
||
(y
>=1
0) tr
ue
Itrever
sest
he
stateofthe
operand
―((
x>5)&&
(y<5))
‖
I
f―((
x>5)
&&(y<5))
‖is
tr
ue,logi
cal
NOTo pe
rato
r
lo
gic
al makesit
fal
se
3 ! NOT !
((x
>5)
&&(
y<5)
)
EXAMPLEPROGRAMFORLOGI
CALOPERATORSI
NC:
#i
ncl
ude<
std
io.
h>
i
ntma
in(
)
32
i
ntm=
40,
n=20;
i
nto
=20,
p=30;
i
f(m>
n&&m!
=0)
p
rin
tf(
"&&Op
era
tor:Bo
thc
ond
iti
onsa
ret
rue
\n"
);
i
f(o
>p|
|p!
=20)
p
rin
tf(
"|
|Op
era
tor:On
lyo
nec
ond
iti
oni
str
ue\
n")
;
i
f(!
(m>
n&&m!
=0)
)
p
rin
tf(
"!Op
era
tor:Bo
thc
ond
iti
onsa
ret
rue
\n"
);
e
lse
p
rin
tf(
"!Op
era
tor:Bo
thc
ond
iti
onsa
ret
rue
."\
"
But
,st
atu
sisi
nve
rte
dasfa
lse
\n"
);
OUTPUT:
&&Oper
ator:Bot
hc o
ndi
ti
onsaretru
e
|
|Ope
rato
r:On l
yonecon
diti
onist
rue
!Ope
rat
or:Bothcondi
ti
onsaretr
ue.Bu
t,s
tat
usi
sin
ver
teda
sfa
lse
I
nthi
sprogram,o
per
ato
rs(
&&,|
|an
d!)a
reu
sedt
ope
rfo
rml
ogi
calo
per
ati
onso
nthegi
ven
e
xpre
ssi
ons.
33
&& o perato
r–―ifclau s
e‖bec
ome strueonl
ywhenbothcond
iti
ons(m>nandm!= 0)istr
ue.El
se,it
bec
o mesfa l
se.
||
Ope r
ator–―ifc l
ause‖bec
ome struewhenanyoneo
ft heco
ndit
ion(o>
p||p!=20)istru
e.Itb
ecomes
fal
sewhe nn on
eo fthec o
ndi
tionistrue.
!Op erator–Itisusedtoreverse
sthes ta
teoftheo
perand.
I
ft heco n
diti
ons(m>n&&m! =0)istrue,tru
e(1
)isr
eturne
d.Thisv a
luei
sinv
e r
tedb y―!‖op
erato
r.
So,―!( m>nandm! =0)‖r
etur
nsf als
e(0).
BI
TWI
SEOPERATORSI
NC
Theseope
rator
sareusedtope
rfor
mb itoper
ati
ons
.Deci
malva
lue
sarecon
ver
tedi
ntobi
naryv
alu
es
whicharetheseq
uenc
eo fbi
tsan
db i
twiseoper
ato
rswor
ko nt
heseb
its
.
Bitwis
eoperat
orsinClangu
ageare&( b
itwi
seAND),|(
bit
wis
eOR),~(bi
twi
seOR),^(XOR)
,
<<(l
eftshi
ft)and>>(ri
ghtshi
ft)
.
TRUTHTABLEFORBI
TWI
SEOPERATI
ONBI
TWI
SEOPERATORS
x x
& ^
x y x
|y y y Op
era
tor
_sy
mbo
l Op
era
tor
_na
me
0 0 0 0 0 & Bi
twi
se
_AND
0 1 1 0 1 | Bi
twi
seOR
1 0 1 0 1 ~ Bi
twi
se
_NOT
1 1 1 1 0 ^ XOR
<
< Le
ftShi
ft
>
> Ri
ghtShi
ft
Cons
iderx=
40a
ndy
=80.Bi
nar
yfo
rmo
fthe
sev
alu
esa
regi
ven
bel
ow.x
=001
01000
y=0101
0000
34
Allb i
twiseopera
tionsforxa n
dya regiv
enb el
ow.
x&y=00000000( b i
nary
)=0( deci
mal)
x|
y=01 11
1000(binary)=120(dec
imal)
~x=1 11
11
11
11
11
1
11
111
11
11
111
111
11
111
11
11
11
11
11
11
11
11
11
11
11
11
11
0101
11
... .=-41(d
ecimal)
x^y=01 1
11
000(b i
nary)=120(deci
mal)x<<1
=01 01
0000(binary)=80(dec
imal)
x> >1=00010100(b i
nary
)=20( de
cimal
)
Note:
BitwiseNOT:Va lueof40inbi
nar
y
i
s000000000000000000000000000000000000000000000000001
0100000000000.So,all0‘s
are
conve
rtedint
o1‘si
nb i
twis
eNOTo pe
rati
on.
Bitwiseleftshi
ftandri
ghtshi
ft:I nl
eftshiftoper
ati
on―x<<1―,1meansthatthebit
swi
llbeleft
shift
edb yonepla
ce.Ifweusei
tas―x< <2―,t he
n,itmeanstha
ttheb i
tswi
llbeleftshi
fte
db y2
place
s.
EXAMPLEPROGRAMFORBI
TWI
SEOPERATORSI
NC
I
nthisexa
mplepro
gra
m,b
itwi
seo
per
ati
onsa
rep
erfo
rme
dass
howna
bov
ean
dou
tpu
tisd
isp
lay
edi
n
d
eci
ma lfo
rmat.
#in
clude<s
tdi
o.h>
i
ntma
in(
)
i
ntm=4
0,n=80,
AND_o
pr,
OR_o
pr,
XOR_o
pr,
NOT_o
pr;
AND_o
pr=(
m&n
);
OR_o
pr=(
m|n
);NOT_o
pr
=(
~m)
;XOR_o
pr=(
m^n
);
p
rin
tf(
"AND_o
prv
alu
e=%d
\n"
,AND_o
pr)
;
p
rin
tf(
"OR_o
prv
alu
e=%d
\n"
,OR_o
pr)
;
p
rin
tf(
"NOT_o
prv
alu
e=%d
\n"
,NOT_o
pr)
;
35
p
rin
tf(
"XOR_o
prv
alu
e=%d
\n"
,XOR_o
pr)
;
p
rin
tf(
"l
eft
_shi
ftv
alu
e=%d
\n"
,m<
<1)
;
p
rin
tf(
"ri
ght
_shi
ftv
alu
e=%d
\n"
,m>
>1)
;
OUTPUT:
AND_o p
rv alu
e=0OR_o pr
va
lue=120NOT_o p
rval
ue=
-41XOR_o prval
ue=120
l
eft_shi
ftv al
ue=80
ri
ght_shiftval
ue=20
CONDI
TIONALORTERNARYOPERATORSI
NC
Con
dit
ion
alope
rat
orsre
turnon
eval
ueifcond
iti
oni
struea
ndr
etu
rnsa
not
herv
alu
eisc
ond
iti
oni
s
fal
se.
Thi
sopera
tori
sals
ocal
ledaste
rna
ryoper
ator.
Syn
tax : ( Con
dit
io
n?t r
ue_va
lue
:fal
se_val
ue)
;
Ex
amp
le: (
A>1
00?0:
1)
;
I
nabo
veexampl
e,i
fAi sgr
eat
ert
han1
00,0i
sre
tur
nede
lse1i
sre
tur
ned
.Thi
sise
qua
ltoi
fel
se
c
ond
iti
ona
lsta
teme
nts
.
EXAMPLEPROGRAMFORCONDI
TIONAL/TERNARYOPERATORSI
NC
#in
clu
de<
std
io.
h>i
nt
ma
in(
)
i
ntx
=1,y
;
y=(x=
=1?2:0);
p
rin
tf(
"xv
alu
eis%d
\n"
,x)
;
p
rin
tf(
"yv
alu
eis%d
",y
);
36
}
OUTPUT:
xv
alu
eis1
yv
alu
eis2
C–I
ncr
eme
nt/d
ecr
eme
ntOp
era
tor
sPREVNEXT
I
ncre
mentop
erat
orsareu
sedtoin
crea
setheval
ueofthev
aria
bleb
yon
ean
dde
cre
men
top
era
tor
s
ar
eusedtod
ecre
asethev
alueofthevar
iab
lebyonei
nCprogr
ams.
Syn
tax:
I
ncre
mentop
erat
or:++var_na
me; (o
r)var_n
ame++;
Dec
remen
toper
ator
:–- v
ar_name;(o
r)var_n
ame–-;
Exa
mp l
e:
I
ncr
ementope
rat
or:++i; i++;
De
cremento
pera
tor:––i;i––;
EXAMPLEPROGRAMFORI
NCREMENTOPERATORSI
NC
I
nthi
spro
gram,val
ueo
f―i
‖isin
creme
nte
don
ebyo
nefr
om1u
pto9u
sin
g―i
++‖o
per
ato
ran
dou
tpu
t
i
sdi
spl
aye
da s―123456789‖ .
//Exa
mplefori
ncr
eme
nto
p e
rato
rs
#i
ncl
ude<
std
io.
h>
i
ntma
in(
)
i
nti
=1
;
whi
le
(i
<1
0)
p
rin
tf(
"%d"
,i
);
i
++;
37
OUTPUT:
123456789
EXAMPLEPROGRAMFORDECREMENTOPERATORSI
NC
I
nthi
sprogr
am,val
ueo
f―I‖i
sde
cre
ment
edoneb
yon
efr
om20u
pto1
1us
ing―i
–‖o
per
ato
ran
dou
tpu
t
i
sdis
pla
yedas―20191
817161
514131
211‖
.
//Ex
amp
lefo
rde
cre
men
top
era
tor
s
#i
ncl
ude<
std
io.
h>
i
ntma
in(
)
i
nti
=20;
whi
le
(i
>1
0)
p
rin
tf(
"%d"
,i
);
i
--;
OUTPUT:
201
9181
7161
5141
3121
1
DI
FFERENCEBETWEENPRE/POSTI
NCREMENT&DECREMENTOPERATORSI
NC
Be
lowt
abl
ewi
lle
xpl
ai
nthed
iffe
ren
ceb
etwe
enp
re/p
osti
ncr
eme
nta
ndd
ecr
eme
nto
per
ato
rsi
nC.
S.
no Op
era
tort
ype Op
era
tor De
scr
ipt
ion
1 Pr
ein
cre
men
t
++i Va
lueo
fii
s
38
i
ncr
emen
tedbe
for
e
a
ssi
gni
ngitt
ovar
iab
le
i
.
Val
ueofiis
i
ncre
mente
daft
er
i
++ as
si
gnin
gittov
ari
abl
e
2 Po
st–
inc
reme
nt i
.
Val
ueofii
s
de
cre
ment
edbefor
e
—–
i as
si
gni
ngitt
ov a
ria
ble
3 Pr
ede
cre
men
t i
.
Val
ueofii
s
de
cre
ment
edaft
er
i
–— as
si
gni
ngitt
ovari
abl
e
4 Po
st_d
ecr
eme
nt i
.
EXAMPLEPROGRAMFORPRE–I
NCREMENTOPERATORSI
NC
//Ex
amp
lefo
rin
cre
men
top
era
tor
s
#i
ncl
ude<
std
io.
h>
i
ntma
in(
)
i
nti
=0;
whi
le
(++i
<5)
p
rin
tf(
"%d"
,i
);
r
etu
rn0;
39
OUTPUT:
1234
Step1:Inabo
vepr
ogram,val
ueof―i ‖isi
ncre
ment
edfrom0t o1us
ingpre
-in
creme
nto
pera
tor
.
Step2:
This
inc
reme
nted
val
ue―1‖i
sco
mp a
redwi
th5i
nwhil
eexpr
ess
io
n.Ste
p3:
Then,thi
si
ncr
emen
tedval
ue―1
‖i
sa s
si
gnedtothev
ari
abl
e―i
‖.
Above3ste
psarec
onti
nue
du n
tilwhil
eexpre
ssi
onbe
comesfals
eandoutp
uti
sdisp
lay
edas
―1234‖.
EXAMPLEPROGRAMFORPOST–I
NCREMENTOPERATORSI
NC
#i
ncl
ude<
std
io.
h>
i
ntma
in(
)
i
nti
=0;
whi
le
(i
++<5)
p
rin
tf(
"%d"
,i
);
r
etu
rn0;
OUTPUT:
12345
Step1:Inthispro
gram,valu
eo fi―0‖i scomp
aredwit
h5i nwhilee
xpre
ssi
on.
Step2:The n,val
ueof―i
‖i
sincre
mented
from0t o1usi
ngpost
-inc
reme
nto
per
ato
r.Step3:
Then,thi
si
ncrement
edvalu
e―1‖i
sass
ignedtothe
vari
abl
e―i
‖.
Above3ste
p sareco
nti
nuedunti
lwhileexpre
ssi
onbec
omesfalseando
utp
utisdi
spl
ayeda
s
―12345‖.
4
0
EXAMPLEPROGRAMFORPRE–DECREMENTOPERATORSI
NC
#i
ncl
ude<
std
io.
h>
i
ntma
in(
)
i
nti
=1
0;
whi
le
(--
i>5)
p
rin
tf(
"%d"
,i
);
r
etu
rn0;
OUTPUT:
9876
Ste
p1:I nabo
vep r
ogram,val
ueo f―i‖isdecr
ementedfrom1 0to9usi
n gpr
e-d
ecr
ement
ope
rato
r.
Ste
p2:This
decr
e me
nted
valu
e―9‖ i
sco
mp a
redwit
h5inwhil
eexpres
sio
n.Step3:
Then,t
hisd
ecrement
edval
ue―9‖isass
ignedtothev
ari
a b
le―i
‖.
Above3ste
psareconti
nue
du n
tilwhil
eexpress
ionbec
omesfa lseando
utputi
sdi
spl
aye
das
―9876‖.
EXAMPLEPROGRAMFORPOST–DECREMENTOPERATORSI
NC:
#in
clu
de<
std
io.
h>
i
ntma
in(
)
i
nti
=1
0;
whi
le
(i
-->5)
4
1
p
rin
tf(
"%d"
,i
);
r
etu
rn0;
OUTPUT:
9876
Ste
p1:Inthispro
gram,valueofi ―10‖isco
mp a
redwith5i nwhileex
pres
sio
n.
Ste
p2:The n,val
ueof―i
‖i
sdecrement
edfr o
m1 0to9usi
ngp o
st-d
ecreme
ntoper
ato
r.Step3:
Then
,thi
sdecre
mente
dv a
lue―9‖i
sassi
gnedtotheva
riabl
e―i
‖.
Abov
e3ste
p sareco
nti
nueduntilwhil
eexpres
sio
nb ec
omesfa l
seandout
putisdi
spl
aye
da s
―98765‖.
SPECI
ALOPERATORSI
NC:
Be
lowa
res
omeo
fsp
eci
alo
per
ato
rst
hatCl
angu
ageo
ffe
rs.
S.
no Op
era
tor
s De
scr
ipt
ion
Thisi
suse
dtoge
tthea
ddr
esso
f
theva
ria
ble
.
Exa
mple:&awi
llgi
vea
ddr
ess
1 & ofa.
Thi
sisuse
dasp
oin
tert
oa
var
iab
le.
Exa
mp l
e :*a whe re
,*i
s
2 * po
int
ertot
heva
ria
ble
a.
Thi
sgive
sthes
izeo
fthe
var
iab
le.
Ex
ample:s
izeo
f(c
har
)wi
ll
3 Si
zeo
f() gi
veu
s1.
4
2
EXAMPLEPROGRAMFOR&AND*OPERATORSI
NC
I
nthi
spro
gram,―&‖s
ymbol
is
use
dtoget
the
addre
sso
fthe
vari
abl
ean
d―*
‖sy
mboli
suse
dtogett
hev
alu
e
o
ft hevari
abl
et hatt
hepoin
terispoi
nti
ngt o
. Plea
ser e
ferC – p
oin
tertop
ict
okn
owmor
e
ab
o u
tpo
int
ers.
#i
ncl
ude<st
dio
.h>
i
ntma
in(
)
i
nt*
ptr
,q;
q=50;
/*a
ddr
esso
fqi
sas
si
gne
dtop
tr*
/
p
tr=&q
;
/*d
isp
layq
'sv
alu
eus
ingp
trv
ari
abl
e*/
p
rin
tf(
"%d
",*
ptr
);
r
etu
rn0;
OUTPUT:
50
EXAMPLEPROGRAMFORSI
ZEOF(
)OPERATORI
NC
s
ize
of()op
era
torisu
sedt
ofi
ndt
heme
mor
ysp
acea
llo
cat
edfo
rea
chCd
atat
ype
s.
#i
nclu
d e<
std
io.
h>
#i
ncl
ude<
li
mit
s.h>
i
ntma
in(
)
i
nta
;
c
harb
;
4
3
fl
oatc
;
d
oub
led
;
p
rin
tf(
"St
ora
ges
izefo
rin
tda
tat
ype
:%d\
n",
siz
eof(
a)
);
p
rin
tf(
"St
ora
ges
izefo
rcha
rda
tat
ype
:%d\
n",
siz
eof(
b))
;
p
rin
tf(
"St
ora
ges
izefo
rfl
oatd
atat
ype
:%d\
n",
siz
eof(
c)
);
p
rin
tf(
"St
ora
ges
izefo
rdo
ubl
eda
tat
ype
:%d
\n"
,si
zeo
f(d
))
;
r
etu
rn0;
OUTPUT:
St
ora
ges
izefo
rintda
tatype:
4
St
ora
ges
izefo
rchardat
at y
pe:1
St
ora
ges
izefo
rfloa
tdatatype
:4
St
ora
ges
izefo
rdoubl
edatatype
:8
EXPRESSI
ONS
Ar
ithme
ti
cex
pre
ssi
oni
nCi
sac
omb
ina
tio
nofv
ari
abl
es,c
ons
tan
tsa
ndo
per
ato
rswr
itt
eni
nap
rop
er
s
ynt
ax.Cc
ane
asi
lyha
ndl
ean
yco
mpl
exma
the
mat
ic
ale
xpr
ess
ion
sbu
tthe
sema
the
mat
ic
ale
xpr
ess
ion
s
ha
vet
obewr
itt
eni
nap
rop
ers
ynt
ax.So
mee
xamp
leso
fma
the
mat
ic
ale
xpr
ess
ion
swr
itt
eni
npr
ope
r
s
ynt
axo
fCa
re
No
te:Cd
oesn
otha
vea
nyo
per
ato
rfo
rex
pon
ent
iat
io
n.
COPERATORPRECEDENCEANDASSOCI
ATI
VITY
Co
per
ato
rsi
nor
de fp
ro r
ece
den
ce(
highe
stt
olo
wes
t).The
ira
sso
cia
tiv
ityi
ndi
cat
esi
nwha
tor
der
o
per
ato
rso
feq
ualp
rec
ede
ncei
nane
xpr
ess
iona
rea
ppl
ie
d.
Op
erator Descript
ion Ass
oci
ati
vi
ty
() Pare
nthes
es(func
tio
ncall
)(seeNote1) l
eft
-to
-ri
ght
[] Brac
kets(a
rraysubs
crip
t)
. Membersel
ecti
onvi
aobjectnameMe mber
-> se
lec
tionvi
apoi
nter
++- - Pos
tfixin
crement
/decr
eme n
t(seeNote2)
4
4
++- - Pr
efixincrement/dec r
e men t r
ight
-to
-le
ft
+- Un
ar yplus
/mi n
u s
!~ Lo
gicalnegati
on /bi
twi sec omplement
(t
ype) Ca
st( c
onvertvaluetot emp oraryva l
u ft
eo ype)
* De
reference
& Addres
s(ofo pe
r and)
si
zeo
f De
termines i
zeinb yteso nthisimp l
emen
tat
io
n
*/% Mul
tipli
catio
n/divis
ion/mo dulu
s l
eft
-to
-ri
ght
+- Addi
tio
n/su b
tractio
n l
eft
-to
-ri
ght
<
<>> Bi
twiseshiftleft,Bi twises hi
ftr i
ght l
eft
-to
-ri
ght
<<= Re
latio
nallesstha n
/l esstha nore qu
alt
o l
eft
-to
-ri
ght
>>= Re
latio
nalgr e
at erthan /gr eat
erthanoreq
ualto
==!= Re
latio
nalisequa lto/isn otequalto l
eft-
to-r
ight
& Bi
twiseAND l
eft-
to-r
ight
^ Bi
twiseexclus
iveOR l
eft-
to-r
ight
| Bi
twiseinc
lusiv
eOR l
eft-
to-r
ight
&& Lo
gicalAND l
eft-
to-r
ight
|| Lo
gicalOR l
eft-
to-r
ight
?: Te
rnaryc o
n di
ti
on al r
ight-
to-l
eft
= As
signment r
ight-
to-l
eft
+=-= Addi
tio
n/su b
tractio
na ss i
gn ment
*
=/= Mul
tipli
catio
n/divis
iona ssignmen t
%=&= Modulus
/bitwis
eANDa ssi
gn ment
^=|= Bi
twiseexclus
ive/inclusiveORa ss
ignme
nt
<
<=>>= Bi
twiseshiftleft/righta s si
gnment
, Co
mma( separatee x
p ressions) l
eft
-to
-ri
ght
No
te1
:
Pare
nthes
esar
eal
souse
dtogrou
psub-ex
pre
ssi
onst
oforc
eadiffe
ren
t
pr
eceden
ce;s
uchpa
rent
het
ica
lexpr
ess
ion
scanbene
ste
danda
re
ev
alua
tedfro
minn
ertoout
er.
No
te2:
Post
fixinc
rement
/dec
rementha
vehighpre
c e
denc
e,b u
tt heact
u al
i
ncrementorde
cremen
toftheoper
andisde
layed(
tobeacc o
mplishe
d
some
timebefor
ethestat
ementc
omplet
esex
ecuti
on)
.Soi nthestateme
nty=
x*z++;t hecurr
entval
ueofzisuse
dtoevalu
atetheexpress
ion(i
.e.
,
z++e v
aluat
estoz)an
dzo n
lyin
crement
edafte
ra l
lels
eisd o
ne.
4
5
EVALUATI
ONOFEXPRESSI
ON
Atfi
rst
,thee
xpr
ess
ion
swi
thi
npa
ren
the
si
sar
eev
alu
ate
d.I
fnop
are
nthe
si
sisp
res
ent
,the
nthe
a
rit
hme
ti
cex
pre
ssi
oni
sev
alu
ate
dfr
oml
eftt
ori
ght
.The
rea
ret
wop
rio
rit
yle
vel
sofo
per
ato
rsi
nC.
Hi
ghp
rio
rit
y:*/%
Lo
wpr
ior
ity
:+-
Thee
val
uat
io
npr
oce
dur
eofa
nar
ithme
ti
cex
pre
ssi
oni
ncl
ude
stwol
eftt
ori
ghtp
ass
est
hro
ught
he
e
nti
ree
xpr
ess
ion
.Int
hefi
rstp
ass
,thehi
ghp
rio
rit
yop
era
tor
sar
eap
pli
eda
sthe
yar
een
cou
nte
red
a
ndi
nthes
eco
ndp
ass
,lo
wpr
ior
ityo
per
ati
onsa
rea
ppl
ie
dast
heya
ree
nco
unt
ere
d.Su
ppo
se,weha
ve
a
nar
ithme
ti
cex
pre
ssi
ona
s:
x=9–1
2/3+3*
2-1
Thi
sex
pre
ssi
oni
sev
alu
ate
dint
wol
eftt
ori
ghtp
ass
esa
s:
Fi
rstPa
ss
St
ep1
:x=9-
4+3*2–1
St
ep2:x=9–4+6–1
Se
con
dPa
ss
St
ep1
:x=5+6–1
St
ep2:x=1
1–1
St
ep3:x=1
0
Bu
twhe
npa
ren
the
si
sisu
sedi
nthes
amee
xpr
ess
ion
,theo
rde
rofe
val
uat
io
nge
tsc
han
ged
.
Fo
rex
amp
le,
x=9–1
2/(
3+3)*(
2–1
)
Whe
npa
ren
the
sesa
rep
res
entt
hent
hee
xpr
ess
ioni
nsi
det
hep
are
nthe
si
sar
eev
alu
ate
dfi
rstfr
om
l
eftt
ori
ght
.Thee
xpr
ess
ioni
sno
wev
alu
ate
dint
hre
epa
sse
sas
:
Fi
rstPa
ss
St
ep1
:x=9–1
2/6*(
2–1
)
St
ep2:x
=9–1
2/6*1
Se
con
dPa
ss
St
ep1
:x=9–2*1
St
ep2:x=9–2
Thi
rdPa
ss
4
6
St
ep3:
x=7
The
rema
yev
ena
ris
eac
asewhe
ren
est
edp
are
nthe
sesa
rep
res
ent(
i.
e.p
are
nthe
si
sin
sid
epa
ren
the
si
s)
.
I
nsu
chc
ase
,thee
xpr
ess
io
nin
sid
ethei
nne
rmo
sts
eto
fpa
ren
the
sesi
se
val
uat
ed
fi
rsta
ndt
hent
heo
ute
rpa
ren
the
sesa
ree
val
uat
ed.
Fo
rex
amp
le,weha
vea
nex
pre
ssi
ona
s:
x=9–(
(1
2/3)+3*2)–
1
Thee
xpr
ess
ioni
sno
wev
alu
ate
das
:
Fi
rstPa
ss:
St
ep1
:x=9–(
4+3*2)–1
St
ep2:x
=9–(
4+6)–1
St
ep3:x
=9–1
0-1
Se
con
dPa
ss
St
ep1
:x=-1–1
St
ep2:x=-
2
No
te:Then
umb
ero
fev
alu
ati
ons
tep
sise
qua
ltot
hen
umb
ero
fop
era
tor
sint
hea
rit
hme
ti
c
e
xpr
ess
ion
.
TYPECONVERSI
ONI
NEXPRESSI
ONS
Whe
nva
ria
ble
san
dco
nst
ant
sofd
iffe
ren
tty
pesa
rec
omb
ine
dina
nex
pre
ssi
ont
hent
heya
re
c
onv
ert
edt
osa
med
atat
ype
.Thep
roc
esso
fco
nve
rti
ngo
nep
red
efi
nedt
ypei
ntoa
not
heri
sca
lle
dty
pe
c
onv
ers
ion
.
Ty
pec
onv
ers
ioni
ncc
anb
ecl
ass
ifi
edi
ntot
hefo
ll
owi
ngt
wot
ype
s:
I
mpl
ic
itTy
peCo
nve
rsi
on
Whe
nthet
ypec
onv
ers
ioni
spe
rfo
rme
dau
toma
tic
all
ybyt
hec
omp
il
erwi
tho
utp
rogr
amme
r‘s
i
nte
rve
nti
on,s
ucht
ypeo
fco
nve
rsi
oni
skn
owna
simp
lic
itt
ypec
onv
ers
iono
rty
pep
romo
tio
n.The
c
omp
il
erc
onv
ert
sal
lop
era
ndsi
ntot
hed
atat
ypeo
fthel
arge
sto
per
and
.
Thes
equ
enc
eofr
ule
stha
tar
eap
pli
edwhi
lee
val
uat
inge
xpr
ess
ion
sar
egi
venb
elo
w:Al
l
s
hor
tan
dcha
rar
eau
toma
tic
all
yco
nve
rte
dtoi
nt,t
hen
,
I
fei
the
roft
heo
per
andi
soft
ypel
ongd
oub
le,t
heno
the
rswi
llb
eco
nve
rte
dtol
ongd
oub
lea
nd
r
esu
ltwi
llb
elo
ngd
oub
le.
El
se,i
fei
the
roft
heo
per
andi
sdo
ubl
e,t
heno
the
rsa
rec
onv
ert
edt
odo
ubl
e.
4
7
El
se,i
fei
the
roft
heo
per
andi
sfl
oat
,the
not
her
sar
eco
nve
rte
dtofl
oat
.
El
se,i
fei
the
roft
heo
per
andi
sun
sign
edl
ongi
nt,t
heno
the
rswi
llb
eco
nve
rte
dtou
nsi
gne
dlo
ngi
nt.
El
se,i
fon
eoft
heo
per
andi
slo
ngi
nt,a
ndt
heo
the
risu
nsi
gne
din
t,t
hen
i
fal
ongi
ntc
anr
epr
ese
nta
llv
alu
eso
fanu
nsi
gne
din
t,t
heu
nsi
gne
din
tisc
onv
ert
edt
olo
ngi
nt.o
the
rwi
se
,
b
otho
per
and
sar
eco
nve
rte
dtou
nsi
gne
dlo
ngi
nt.
El
se,i
fei
the
rop
era
ndi
slo
ngi
ntt
heno
the
rwi
llb
eco
nve
rte
dtol
ongi
nt.
El
se,i
fei
the
rop
era
ndi
sun
sign
edi
ntt
heno
the
rswi
llb
eco
nve
rte
dtou
nsi
gne
din
t.
I
tsho
uldb
eno
tedt
hatt
hefi
nalr
esu
lto
fex
pre
ssi
oni
sco
nve
rte
dtot
ypeo
fva
ria
bleo
nle
fts
ideo
f
a
ssi
gnme
nto
per
ato
rbe
for
eas
si
gni
ngv
alu
etoi
t.
Al
so,c
onv
ers
iono
ffl
oatt
oin
tca
use
str
unc
ati
ono
ffr
act
io
nalp
art
,co
nve
rsi
ono
fdo
ubl
etofl
oat
c
aus
esr
oun
din
gofd
igi
tsa
ndt
hec
onv
ers
io
nofl
ongi
ntt
oin
tca
use
sdr
opp
ingo
fex
ces
shi
ghe
ror
der
b
its
.
Ex
pli
ci
tTy
peCo
nve
rsi
on
Thet
ypec
onv
ers
ionp
erfo
rme
dbyt
hep
rogr
amme
rbyp
osi
ngt
hed
atat
ypeo
fthee
xpr
ess
iono
f
s
pec
ifi
cty
pei
skn
owna
sex
pli
ci
tty
pec
onv
ers
ion
.
Thee
xpl
ic
itt
ypec
onv
ers
ioni
sal
sokn
owna
sty
pec
ast
ing.
Ty
pec
ast
ingi
nci
sdo
nei
nthefo
ll
owi
ngfo
rm:
(
dat
a_t
ype
)ex
pre
ssi
on;
whe
re,d
ata
_ty
pei
san
yva
li
dcd
atat
ype
,ade
n x
pre
ssi
onma
ybec
ons
tan
t,v
ari
abl
eor
e
xpr
ess
ion
.
Fo
rex
amp
le,x
=(i
nt)
a+b
*d;
Thefo
ll
owi
ngr
ule
sha
vet
obefo
ll
owe
dwhi
lec
onv
ert
ingt
hee
xpr
ess
ionfr
omo
net
ypet
oan
othe
rto
a
voi
dthel
osso
fin
for
mat
io
n:
Al
lin
tege
rty
pest
obec
onv
ert
edt
ofl
oat
.
Al
lfl
oatt
ype
stob
eco
nve
rte
dtod
oub
le.
Al
lcha
rac
tert
ype
stob
eco
nve
rte
dtoi
nte
ger
.
4
8
FORMATTEDI
NPUTANDOUTPUT
TheCPr
ogr
ammi
ngLa
ngu
agei
sal
soc
all
edt
heMo
the
rofl
angu
age
s.TheCl
angu
agewa
s
d
eve
lop
edb
yDe
nni
sRi
tc
hieb
etwe
en1
969a
nd1
973a
ndi
sas
eco
nda
ndt
hir
dge
ner
ati
ono
fla
ngu
age
s.
TheCl
angu
agep
rov
ide
sbo
thl
owa
ndhi
ghl
eve
lfe
atu
resi
tpr
ovi
desb
otht
hep
owe
rofl
ow-
lev
el
l
angu
age
san
dthefl
exi
bi
li
tya
nds
imp
li
ci
tyo
fhi
gh-
lev
ell
angu
age
s.
Cp
rov
ide
sst
and
ardfu
nct
io
nss
can
f()a
ndp
rin
tf(
),fo
rpe
rfo
rmi
ngfo
rma
tte
din
puta
ndo
utp
ut.
The
sefu
nct
io
nsa
cce
pt,a
spa
rame
ter
s,afo
rma
tsp
eci
fi
cat
io
nst
rin
gan
dal
is
tofv
ari
abl
es.
Thefo
rma
tsp
eci
fi
cat
io
nst
rin
gisac
har
act
ers
tri
ngt
hats
pec
ifi
est
hed
atat
ypeo
fea
chv
ari
abl
eto
b
ein
puto
rou
tpu
tan
dthes
izeo
rwi
dtho
fthei
npu
tan
dou
tpu
t.
No
wtod
isc
ussfo
rma
tte
dou
tpu
tinfu
nct
io
ns.
Fo
rma
tte
dOu
tpu
t
Thefu
nct
io
npr
int
f()i
sus
edfo
rfo
rma
tte
dou
tpu
ttos
tan
dar
dou
tpu
tba
sedo
nafo
rma
tsp
eci
fi
cat
io
n.
Thefo
rma
tsp
eci
fi
cat
io
nst
rin
g,a
lon
gwi
tht
hed
atat
obeo
utp
ut,a
ret
hep
ara
met
erst
othep
rin
tf(
)
fu
nct
io
n.
Sy
nta
x:
p
rin
tf(
for
mat
,da
ta1
,da
ta2,
… )
;
I
nthi
ssy
nta
xfo
rma
tist
hefo
rma
tsp
eci
fi
cat
io
nst
rin
g.Thi
sst
rin
gco
nta
ins
,fo
rea
chv
ari
abl
eto
b
eou
tpu
t,as
pec
ifi
cat
io
nbe
gin
nin
gwi
tht
hes
ymb
ol%fo
ll
owe
dbyac
har
act
erc
all
edt
hec
onv
ers
ion
c
har
act
er.
Ex
amp
le:
p
rin
tf(
―%c
‖,d
ata
1)
;
Thec
har
act
ers
pec
ifi
eda
fte
r%i
sca
lle
dac
onv
ers
ionc
har
act
erb
eca
usei
tal
lo
wso
ned
atat
ypet
obe
c
onv
ert
edt
oan
othe
rty
pea
ndp
rin
ted
.
Se
ethefo
ll
owi
ngt
abl
eco
nve
rsi
onc
har
act
era
ndt
hei
rme
ani
ngs
.
Co
nve
rsi
on Me
ani
ng
Cha
rac
ter
d Thed
atai
sco
nve
rte
dtod
eci
mal(
in
tege
r)
c Thed
atai
sta
kena
sac
har
act
er.
s Thed
atai
sas
tri
nga
ndc
har
act
erfr
omt
hes
tri
ng,a
rep
rin
tedu
nti
laNULL,
c
har
act
eri
sre
ache
d.
4
9
f Thed
atai
sou
tpu
tasfl
oato
rdo
ubl
ewi
thad
efa
ultPr
eci
si
on6.
Sy
mbo
ls Me
ani
ng
\
n Fo
rne
wli
ne(
li
nefe
edr
etu
rn)
\
t Fo
rta
bsp
ace(
equ
iva
len
tof8s
pac
es)
Ex
amp
le
p
rin
tf(
―%c
\n‖,
dat
a1)
;
Thefo
rma
tsp
eci
fi
cat
io
nst
rin
gma
yal
soha
vet
ext
.
Ex
amp
le
p
rin
tf(
―Cha
rac
teri
s:‖
%c\
n‖,d
ata
1)
;
Thet
ext"
Cha
rac
teri
s:"i
spr
int
edo
uta
lon
gwi
tht
hev
alu
eofd
ata
1.
Ex
amp
lewi
thp
rogr
am
#i
ncl
ude
<st
dio
.h>
#in
clu
de
<
con
io.
h>Ma
in(
)
{
Cha
ral
pha
bh=
"A"
;in
t
n
umb
er1
=55;fl
oat
n
umb
er2=
22.
34;
p
rin
tf(
―cha
r=%c
\n‖,
alp
hab
h);
p
rin
tf(
―i
nt=%d
\n‖,
numb
er1
);
p
rin
tf(
―fl
oat
=%f\
n‖,
numb
er2)
;
ge
tch(
);
c
lrs
cr(
);
r
etr
un0;
}
Ou
tpu
tHe
re…
c
har=
A
i
nt=55
fl
aot
=22.
34000
0
50
Wha
tist
heo
utp
uto
fthes
tat
eme
nt?
p
rin
tf(
―I
nte
geri
s:%d
;Al
pha
beti
s:%c
\n‖,
numb
er1
,al
pha
);Whe
re
n
umb
er1c
ont
ain
s44a
nda
lphac
ont
ain
s"Kr
ishn
aSi
ngh"
.Gi
vet
he
a
nswe
rbe
low.
Be
twe
ent
hec
har
act
er%a
ndt
hec
onv
ers
io
ncha
rac
ter
,the
rema
ybe
:
Ami
nuss
ign
:De
not
ingl
efta
dju
stme
nto
fthe
dat
a.
Ad
igi
t:Sp
eci
fyi
ngt
hemi
ni
mumwi
dthi
nwhi
cht
hed
atai
stob
eou
tpu
t,i
fthed
ataha
sa
l
arge
rnu
mbe
rofc
har
act
erst
hent
hes
pec
ifi
edwi
dtho
ccu
pie
dbyt
heo
utp
uti
sla
rge
r.I
f
t
hed
atac
ons
is
tso
ffe
werc
har
act
erst
hent
hes
pec
ifi
edwi
dth,i
tisp
add
edt
other
ighto
r
t
othel
eft(
ifmi
nuss
igni
sno
tsp
eci
fi
ed)wi
thb
lan
ks.I
fthed
igi
tisp
refi
xedwi
thaz
ero
,
t
hep
add
ingi
sdo
newi
thz
ero
sin
ste
ado
fbl
anks
.
Ap
eri
od:Se
par
ati
ngt
hewi
dthf
romt
hen
ext
digi
t.
Ad
igi
tfo
ll
owi
ngt
hep
eri
od:s
pec
ify
ingt
hep
rec
isi
on(
numb
ero
fde
cima
lpl
ace
sfo
r
n
ume
ricd
ata
)ort
hema
ximu
mnu
mbe
rofc
har
act
erst
obe
out
put
.
Le
tte
r1:Toi
ndi
cat
etha
tthed
atai
te
misal
ongi
nte
gera
ndn
ota
nin
t.
Fo
rma
tsp
eci
fic
ati
ons
tri
ng Da
ta Ou
tpu
t
|
%2d
| 9 |
9|
|
%2d
| 1
23 |
123|
|
%03d
| 9 |
009|
|
%-2d
| 7 |
7|
|
%5.
3d| 2 |
002|
|
%3.
1d| 1
5 |
15|
|
%3.
5d| 1
5 |
001
5|
|
%5s
| ―Ou
tpu
tst
ing‖ |
Out
puts
tri
ng|
|
%15s
| ―Ou
tpu
tst
ing‖ |
Out
puts
tri
ng|
|
%-1
5s| ―Ou
tpu
tst
ing‖ |
Out
puts
tri
ng|
|
%15.
5s| ―Ou
tpu
tst
ing‖ |
Out
puts
tri
ng|
|
%.5s
| ―Ou
tpu
tst
ing‖ |
Out
put
|
51
|
%15.
5s| ―Ou
tpu
tst
ing‖ |
Out
put
|
|
%f| 87
.65 |
87.
650000|
|
%.4
.1s
| 87
.65 |
87.
71|
Ex
amp
leb
ase
dont
hec
onv
ers
ionc
har
act
er:
#i
ncl
ude
<st
dio
.h>
#i
n
clu
de<
con
io.
h>ma
i
n
()
{
I
ntn
um=
65;
p
rin
tf(
―Va
lue
ofn
umi
s:%d
\n:
,nu
m);
p
rin
tf(
―Cha
rac
tere
qui
val
ento
f%di
s%c
\n‖,n
um,n
um)
;ge
tch(
);
c
lrs
cr(
);
r
eru
rno
;
}
Ou
tpu
tHe
re…
c
har
=A
i
nt=55
fl
aot
=22.
340000
Fo
rma
tte
dIn
put
Thefu
nct
io
nsc
anf(
)isu
sedfo
rfo
rma
tte
din
putfr
oms
tan
dar
din
puta
ndp
rov
ide
sma
nyo
fthe
c
onv
ers
ionfa
cil
it
ie
soft
hefu
nct
io
npr
int
f()
.
Sy
nta
x
s
can
f(fo
rma
t,n
um1
,nu
m2,
……)
;
Thefu
nct
io
nsc
naf(
)re
adsa
ndc
onv
ert
scha
rac
ter
sfr
omt
hes
tan
dar
dsi
npu
tde
pen
din
gont
hef
orma
t
s
pec
ifi
cat
io
nst
rin
gan
dst
ore
sthei
npu
tinme
mor
ylo
cat
io
nsr
epr
ese
nte
dbyt
heo
the
rar
gume
nts(
num1
,
n
um2,
….)
.
Fo
rEx
amp
le:
s
can
f(―%c%d‖,
&Na
me,
&Ro
llNo
);
No
te:t
hed
atan
ame
sar
eli
st
eda
s&Na
mea
nd&Ro
llNoi
nst
eado
fNa
mea
ndRo
llNo
52
r
esp
ect
ive
ly.Thi
sisho
wda
tan
ame
sar
esp
eci
fi
edi
nas
cna
f()fu
nct
io
n.I
nca
seo
fst
rin
gty
ped
ata
n
ame
s,t
hed
atan
amei
sno
tpr
ece
dedb
ythec
har
act
er&.
Ex
amp
lewi
thp
rogr
am
Wr
iteafu
nct
io
ntoa
cce
pta
ndd
isp
layt
hee
leme
ntn
umb
era
ndt
hewe
ighto
fap
rot
on.The
e
leme
ntn
umb
eri
sani
nte
gera
ndwe
ighti
sfr
act
io
nal
.
So
lvehe
re:
#i
ncl
ude
<st
dio
.h>
#i
n
clu
de<
con
io.
h>ma
i
n
()
{
I
nte
_nu
m;
Fl
oat
e_wt
;
p
rin
tf(
―En
ter
the
Ele
men
tNo
.an
dWe
ight
ofa
Pro
ton
\n‖
);
s
can
f(―%d%f‖,
&e_n
um,
&e_wt
);
p
rin
tf(
―TheEl
eme
ntNo
.is
:‖,
e_n
um)
;
p
rin
tf(
―The
Wei
ght
ofa
Pro
ton
is:
%f\
n‖,
e_wt
);
ge
tch(
);
r
etu
rn0;
}
53
UNI
T-I
I
CONTROLSTRUCTURES,ARRAYSANDSTRI
NGS
DECI
SIONSTATEMENTS
I
fst
ate
men
t:
Sy
nta
x:
i
f(e
xpr
ess
ion
)
s
tat
eme
nt1
;
Ex
pla
nat
ion:
Exp
res
si
oni
sBo
ole
anEx
pre
ssi
on
I
tma
yha
vet
rueo
rfa
lse
val
ue
Me
ani
ngo
fIfSt
ate
men
t:
I
tChe
ckswhe
the
rthegi
venEx
pre
ssi
oni
sBo
ole
ano
rno
t!!
I
fEx
pre
ssi
oni
sTr
ueThe
nite
xec
ute
sthes
tat
eme
nto
the
rwi
sej
ump
sto
nex
t_i
nst
ruc
ti
on
Sa
mpl
ePr
ogr
amCo
de:
v
oidmai
n()
{
i
nta=5,
b=6,c
;
c=a+b;
54
i
f(c
==11
)
p
rin
tf("
Exe
cut
eme1
")
;
p
rin
tf(
"Ex
ecu
teme2"
);
}
Ou
tpu
t:
Ex
ecu
teme
1
I
fSt
ate
men
t:
i
f(con
dit
io
nal)
{
Sta
temen
tNo 1
Sta
temen
tNo 2
Sta
temen
tNo 3
.
.
.
Sta
temen
tNoN
}
No
t e:
Mo
ret
hanOn
eCo
ndi
ti
onsc
anb
eWr
itt
eni
nsi
deI
fst
ate
men
t.
1
. Op
eni
nga
ndCl
osi
ngBr
ace
sar
ere
qui
redo
nlywhe
n―Co
de‖a
fte
rifs
tat
eme
nto
ccu
pie
s
mu
lti
pl
el
in
es.
i
f(c
ond
iti
ona
l)
St
ate
men
tNo1
St
ate
men
tNo
2
St
ate
men
tNo
3
I
nthea
bov
eex
amp
leo
nlySt
ate
men
t1i
sap
arto
fifSt
ate
men
t.
1
. Co
dewi
llb
eex
ecu
tedi
fco
ndi
ti
ons
tat
eme
nti
sTr
ue.
2.No
n-Ze
roNu
mbe
rIn
sid
eifme
ans“TRUECo
ndi
ti
on”
i
f(1
00)
p
rin
tf(
"Tr
ueCo
ndi
ti
on"
);
i
f-e
lseSt
ate
men
t:
55
Wec
anu
sei
f-e
lses
tat
eme
nti
ncp
rogr
ammi
ngs
otha
twec
anc
hec
kan
yco
ndi
ti
ona
ndd
epe
ndi
ngo
n
t
heo
utc
omeo
fthec
ond
iti
onwec
anfo
ll
owa
ppr
opr
iat
epa
th.Weha
vet
ruep
atha
swe
lla
sfa
lse
p
ath.
Sy
nta
x:
i
f(e
xpr
ess
ion
)
{
st
ate
ment
1;
st
ate
ment
2;
}
el
se
{
st
ate
ment
1;
st
ate
ment
2;
}
n
ext
_st
ate
men
t;
Ex
pla
nat
io
n:
I
fex
pre
ssi
oni
sTr
uet
henSt
ate
men
t1a
ndSt
ate
men
t2a
ree
xec
ute
d
Ot
her
wis
eSt
ate
men
t3a
ndSt
ate
men
t4a
ree
xec
ute
d.
Sa
mpl
ePr
ogr
amo
nif-
els
eSt
ate
men
t:
voi
dma in
()
{
i
ntma rks=50;
if(marks>=40)
{
p
r i
ntf(
"Stude
nti
sPa
ss"
);
}
else
{
p
r i
ntf(
"Stude
nti
sFa
il
")
;
}
}
Output:
St
ude
nti
sPa
ss
Fl
owc
har
t:I
fEl
seSt
ate
men
t
56
Co
nsi
derEx
amp
le1wi
thEx
pla
nat
io
n:
Co
nsi
derFo
ll
owi
ngEx
amp
le–
i
ntn
um=20;
i
f(n
um= =
20)
{
p
rin
tf(
"TrueBl
ock")
;
}
el
se
{
p
rin
tf(
"Fal
seBlo
c k"
);
}
I
fpartExec
utedi
fCo nd
iti
onSt
ate
men
tisTr
ue.
i
f(n
um=
=20)
{
p
rin
tf(
"Tr
ueBl
ock"
);
}
Tr
ueBl
ockwi
llb
eex
ecu
tedi
fco
ndi
ti
oni
sTr
ue.El
se
Pa
rte
xec
ute
difCo
ndi
ti
onSt
ate
men
tisFa
lse
.el
se
{
p
rin
tf(
"Fa
lseBl
ock"
);
}
Co
nsi
derEx
amp
le2wi
thEx
pla
nat
io
n:
57
Mo
ret
hanOn
eCo
ndi
ti
onsc
anb
eWr
itt
eni
nsi
deI
fst
ate
men
t.
i
ntn
um1=20;
i
ntn
um2=40;
i
f(n
um1==20&&n um2==40)
{
p
rin
tf(
"Tr
ueBloc
k")
;
}
Ope
nin
gandClo
sin
gBr a
cesa
rere
qui
redo
nlywhe
n―Co
de‖a
fte
rifs
tat
eme
nto
ccu
pie
smu
lti
pl
eli
nes
.
Co
dewi
llb
eex
ecu
tedi
fco
ndi
ti
ons
tat
eme
nti
sTr
ue.No
n-Ze
roNu
mbe
rIn
sid
e
i
fme
ans“TRUECo
ndi
ti
on”
I
f-El
seSt
ate
men
t:
i
f(con
dit
io
nal)
{
//Trueco
de
}
el
se
{
//Fal
secode
}
Note:
Co
nsi
derFo
ll
owi
ngEx
amp
le–
i
ntn
um=20;
i
f(n
um= =
20)
{
p
rin
tf(
"TrueBl
ock")
;
}
el
se
{
p
rin
tf(
"Fal
seBlo
c k"
);
}
I
fpartExec
utedi
fCo nd
iti
onSt
ate
men
tisTr
ue.
i
f(n
um=
=20)
{
p
rin
tf(
"Tr
ueBl
ock"
);
}
Tr
ueBl
ockwi
llb
eex
ecu
tedi
fco
ndi
ti
oni
sTr
ue.El
se
Pa
rte
xec
ute
difCo
ndi
ti
onSt
ate
men
tisFa
lse
.
58
e
lse
{
p
rin
tf(
"Fa
lseBl
ock"
);
}
Moretha
nOneCo
ndi
ti
onsc
anb
eWr
itt
eni
nsi
deI
fst
ate
men
t.i
nt
nu
m1=20;
i
ntnum2=40;
i
f(n
um1==20&&n um2==40)
{
p
rin
tf(
"Tr
ueBloc
k")
;
}
Ope
nin
gandClo
sin
gBr a
cesa
rere
qui
redo
nlywhe
n―Co
de‖a
fte
rifs
tat
eme
nto
ccu
pie
smu
lti
pl
eli
nes
.
Co
dewi
llb
eex
ecu
tedi
fco
ndi
ti
ons
tat
eme
nti
sTr
ue.No
n-
Ze
roNu
mbe
rIn
sid
eifme
ans“TRUECo
ndi
ti
on”
Swi
tchs
tat
eme
nt
Whywes
hou
ldu
seSwi
tc
hCa
se?
On
eoft
hec
las
si
cpr
obl
eme
nco
unt
ere
din
nes
tedi
f-e
lse/e
lse
-ifl
add
eri
s
c
all
edp
rob
lemo
fCo
nfu
sio
n.
I
toc
cur
swhe
nnoma
tchi
nge
lsei
sav
ail
abl
efo
rif.
Ast
hen
umb
ero
fal
ter
nat
ive
sin
cre
ase
stheCo
mpl
exi
tyo
fpr
ogr
ami
ncr
eas
es
d
ras
ti
cal
ly.
To
ove
rco
met
his
,CPr
ovi
dea
mul
ti
-wa
yde
cis
ion
sta
teme
ntc
all
ed‗
Swi
tchSt
ate
men
t‗
Se
eho
wdi
ffi
cul
tist
hiss
cen
ari
o?
i
f(Co
ndit
io
n1 )
Stat
ement1
e
lse
{
Stat
ement2
i
f(con
dit
ion2)
{
i
f(c
ondi
tio
n3)
59
s
tatemen
t3
else
if(c
ondi
ti
on4)
{
st
ate
me n
t4
}
}
else
{
sta
t e
ment5
}
}
Fi
rstLookofSwitc
hCa
se
s
witc
h(expr
ess
ion
)
{
c
asevalu
e1:
b
ody1
b
reak;
c
aseva
lue
2:
b
ody
2
b
rea
k;
c
aseva
lue
3:
b
ody
3
b
rea
k;
de
fault:
de
fault-b
ody
br
eak;
}
ne
xt-sta
tement
;
Fl
owDi agra
m:
*
Ste
psa
reSho
wni
nCi
rcl
es.
60
Ho
witwo
rks
?
Swi
tc
hca
sec
hec
kst
hev
alu
eofe
xpr
ess
ion
/va
ria
blea
gai
nstt
hel
is
tofc
asev
alu
esa
ndwhe
n
t
hema
tchi
sfo
und,
theb
loc
kofs
tat
eme
nta
sso
cia
tedwi
tht
hatc
asei
sex
ecu
ted
Ex
pre
ssi
ons
hou
ldb
eIn
tege
rEx
pre
ssi
on/Cha
rac
ter
Br
eaks
tat
eme
ntt
ake
sco
ntr
olo
uto
fthe
cas
e.
Br
eakSt
ate
men
tis
Opt
ion
al.
#incl
ud e
<stdi
o.h>
voi
dma i
n(
)
{
i
ntr oll=3;
switch(roll)
{
case1:
print
f("I amPankaj"
);
break;
case2:
print
f("I amNikhi
l");
break;
case3:
print
f("I amJohn");
break;
default:
print
f(" Nostuden
tfound"
);
break;
}
}
Ase xplai
nedearl
ie
r–
3i
sas
si
gne
dtoi
nte
gerv
ari
abl
e‗r
oll
‗
Onl
in
e5s
wit
chc
ased
eci
des–―Weha
vet
oex
ecu
teb
loc
kofc
odes
pec
ifi
edi
n3r
dca
se―.Swi
tc
h
Ca
see
xec
ute
sco
defr
omt
opt
obo
tto
m.
I
twi
lln
owe
nte
rin
tofi
rstCa
se[
i.ec
ase1
:]
I
twi
llv
ali
dat
eCa
sen
umb
erwi
thv
ari
abl
eRo
ll.I
fno
ma
tchfo
undt
heni
twi
llj
umpt
oNe
xtCa
se.
.
Whe
nitfi
ndsma
tchi
ngc
asei
twi
lle
xec
uteb
loc
kofc
odes
pec
ifi
edi
ntha
tca
se.
LOOPCONTROLSTATEMENTS
Whi
les
tat
eme
nt:
Whi
leLo
opSy
nta
x:
61
i
nit
ial
iz
ati
on;
whi
le(
cond
iti
on)
{
i
ncr
eme
nta
tio
n;
}
No
te:
Fo
rSi
ngl
eLi
neo
fCo
de–Op
eni
nga
ndCl
osi
ngb
rac
esa
ren
otn
eed
ed.whi
le
(1
)
i
sus
edfo
rIn
fin
iteLo
op
I
ni
ti
al
iz
ati
on,I
ncr
eme
nta
tio
nan
dCo
ndi
ti
ons
tep
sar
eond
iffe
ren
tLi
ne.
Whi
leLo
opi
sal
soEn
tryCo
ntr
oll
edLo
op.
[i.
eco
ndi
ti
onsa
rec
hec
kedi
ffo
undt
ruet
hena
ndt
heno
nly
c
odei
sex
ecu
ted]
Dowhi
le
:
Do
-Whi
leLo
opSy
nta
x:
i
ni
ti
al
iz
ati
on;
d
o
{
i
ncr
ementa
tio
n;
}
while
(co
ndi
tio
n);
62
No
te:
I
tisEx
itCo
ntr
oll
edLo
op.
I
ni
ti
al
iz
ati
on,I
ncr
eme
nta
tio
nan
dCo
ndi
ti
ons
tep
sar
eond
iffe
ren
tLi
ne.
I
tisa
lsoc
all
edBo
tto
mTe
ste
d[i
.eCo
ndi
ti
oni
ste
ste
datb
ott
oma
ndBo
dyha
stoe
xec
utea
tle
asto
nce]
Fo
rst
ate
men
t:
Weha
vea
lre
adys
eent
heb
asi
cso
fLo
opi
ngSt
ate
men
tinC.CLa
ngu
agep
rov
ide
susd
iffe
ren
tki
nd
o
flo
opi
ngs
tat
eme
ntss
ucha
sFo
rlo
op,whi
lel
oopa
ndd
o-whi
lel
oop
.Int
hisc
hap
terwewi
llb
e
l
ear
nin
gdi
ffe
ren
tfl
avo
rso
ffo
rlo
ops
tat
eme
nt.
Di
ffe
ren
tWa
yso
fUs
ingFo
rLo
opi
nCPr
ogr
ammi
ng
I
nor
dert
odoc
ert
aina
cti
onsmu
lti
pl
eti
mes
,weu
sel
oopc
ont
rols
tat
eme
nts
.Fo
r
l
oopc
anb
eimp
leme
nte
dind
iffe
ren
tve
rit
ie
sofu
sin
gfo
rlo
op–
Si
ngl
eSt
ate
men
tin
sid
eFo
rLo
op
Mu
lti
pl
eSt
ate
men
tsi
nsi
deFo
rLo
op
NoSt
ate
men
tin
sid
eFo
rLo
op
Se
mic
olo
natt
hee
ndo
fFo
rLo
op
Mu
lti
pl
eIn
iti
al
iz
ati
onSt
ate
men
tin
sid
eFo
r
Mi
ss
ingI
ni
ti
al
iz
ati
oni
nFo
rLo
op
Mi
ss
ingI
ncr
eme
nt/De
cre
men
tSt
ate
men
t
I
nfi
ni
teFo
rLo
op
Co
ndi
ti
onwi
thn
oCo
ndi
ti
ona
lOp
era
tor
.
63
Wa
y1:Si
ngl
eSt
ate
men
tin
sid
eFo
rLo
op
fo
r(i
=0;
i<5;
i++)
p
rin
tf(
"Hel
lo"
);
Abo
veco
desni
ppetwi
llp
rin
tHe
ll
owo
rd5t
ime
s.
Weha
ves
ingl
est
ate
men
tin
sid
efo
rlo
opb
ody
.
Non
eedt
owr
app
rin
tfi
nsi
deo
pen
inga
ndc
los
ingc
url
ybl
ock.
Cu
rlyBl
ocki
sOp
tio
nal
.
Wa
y2:
Mul
ti
pl
eSt
at
eme
nt
si
ns
id
eFo
rLo
op
fo
r(i
=0;i
<5;i
++)
{
pri
ntf(
"St
ate
men
t1"
);
pri
ntf(
"St
ate
men
t2")
;
pri
ntf(
"St
ate
men
t3")
;
i
f(c
ond
iti
on)
{
}
}
I
fwehav
ebl
ocko
fco
det
hati
stob
eex
ecu
tedmu
lti
pl
eti
mest
henwec
anu
sec
url
ybr
ace
stowr
ap
mu
lti
pl
est
ate
men
tinfo
rlo
op.
64
Wa
y3:NoSt
ate
men
tin
sid
eFo
rLo
op
fo
r(i
=0;
i<5;
i++)
{
}
t
his
isb
ody
les
sfo
rlo
op.I
tisu
sedt
oin
cre
men
tva
lueo
f―i
‖.Thi
sve
rit
yoffo
rlo
opi
sno
tus
ed
ge
ner
all
y.
Att
hee
ndo
fab
ovefo
rlo
opv
alu
eofiwi
llb
e5.
Wa
y4:
Semi
co
lo
nat
the
end
ofFo
rLo
op
fo
r(i
=0;
i<5;
i++)
;
Ge
ner
all
ybe
gin
ner
stho
ughtt
hat,wewi
llge
tco
mpi
lee
rro
rifwewr
ites
emi
col
ona
tthee
ndo
f
fo
rlo
op.
Thi
sisp
erfe
ctl
yle
gals
tat
eme
nti
nCPr
ogr
ammi
ng.Thi
s
s
tat
eme
nti
ssi
mil
art
obo
dyl
essfo
rlo
op.(
Way3)
Wa
y5:
Mul
ti
pl
eI
ni
ti
al
i
zat
i
onS
tat
eme
nt
in
si
de
For
fo
r(i
=0,j
=0;i<
5;i++)
{
st
ateme
nt1
;
st
ateme
nt2;
st
ateme
nt3;
}
Mul
ti
plei
niti
al
iza
tio
nsta
teme
ntsmu
stb
ese
per
ate
dbyCo
mmai
nfo
rlo
op.
Way6:
Miss
i
ngI
ncre
men
t/De
cre
men
tSt
at
eme
ntfor(
i=
0;i
<5;
)
{
st
ate
ment1
;
st
ate
ment2;
st
ate
ment3;
i
++;
}
ho
weverwehavetoe
xpli
ci
tlya
lte
rtheval
ueiint
hel
oopb
ody
.
Wa
y7:
Mis
si
ngI
ni
ti
al
i
zat
i
oni
nFo
rLo
opi
=0;
65
fo
r(;
i<5;
i++)
{
st
ateme
nt1
;
st
ateme
nt2;
st
ateme
nt3;
}
wehavet
osetva
lueo
f‗i
‘be
for
een
ter
ingi
nthel
oopo
the
rwi
sei
twi
llt
akega
rba
gev
alu
eof‗
i‘.
Wa
y8:
Inf
in
it
eFo
rLo
opi
=0;
fo
r(;
;)
{
stat
eme
nt1
;
stat
eme
nt2;
sta
teme
nt3;
i
f(b
reaki
ngc
ond
iti
on)
bre
ak;
i
++;
}
I
nfi
ni
tefo
rlo
opmu
stha
veb
rea
kin
gco
ndi
ti
oni
nor
dert
obr
eakfo
rlo
op.o
the
rwi
sei
twi
llc
aus
e
o
ver
flo
wofs
tac
k.
Su
mma
ryo
fDi
ffe
ren
tWa
yso
fImp
leme
nti
ngFo
rLo
op
Fo
rm Co
mme
nt
fo
r(i=0;i<1
0;i
++)
Si
ngl
eSt
ate
men
t
St
ate
ment
1;
fo
r(i=0;i<1
0;i++) Mu
lti
pleSt
ate
men
tswi
thi
nfo
r
{
Sta
teme
nt1
;
Sta
teme
nt2;
Sta
teme
nt3;
}
fo
r(i
=0;i<1
0;i
++); Fo
rLoopwit
hnoBo
dy(
Car
efu
llyLo
oka
tthe
Se
mic
olon
)
fo
r Mu
lti
plei
ni
ti
al
iza
tio
n&Mu
lti
pl
e
66
(i
=0,j
=0;i
<1
00;
i++,
j++) Up
dat
eSt
ate
men
tsSe
par
ate
dbyCo
mma
Stat
emen
t1;
fo
r(;i
<1
0;i
++) I
ni
ti
al
iza
tio
nno
tus
ed
fo
r(;i
<1
0;) I
ni
ti
al
iza
tio
n&Up
dat
eno
tus
ed
fo
r(;;) I
nfi
ni
teLo
op,Ne
verTe
rmi
nat
es
JUMPSTATEMENTS:
Br
eakst
ate
men
t
Br
eakSt
ate
men
tSi
mpl
yTe
rmi
nat
eLo
opa
ndt
ake
sco
ntr
olo
uto
fthel
oop
.
Br
eaki
nFo
rLo
op:
fo
r(i
nit
ial
iz
ati
on;c
ond
iti
on;i
ncr
eme
nta
tio
n)
{
St
atemen
t1;
St
atemen
t2;
br
eak;
}
Br
eaki
nWhi
leLo
op:
i
nit
ial
iz
ati
on;
whi
le(
condi
ti
on)
{
St
atement
1;
St
atement
2;
i
ncre
mentat
ion
br
eak;
}
Br
eakSt
ate
men
tinDo
-Whi
le:
i
nit
ial
iz
ati
on;
do
{
Sta
tement
1;
Sta
tement
2;
i
ncre
mentat
ion
bre
ak;
}whi
le(
cond
iti
on)
;
67
Wa
y1:Do
-Whi
leLo
op
Wa
y2:Ne
ste
dfo
r
Wa
y3:Fo
rLo
op
Wa
y4:Whi
leLo
op
68
Co
nti
nues
tat
eme
nt:
l
oop
{
con
tin
ue;
//cod
e
}
No
te:
I
tisu
sedfo
rski
ppi
ngp
arto
fLo
op.
Co
nti
nuec
aus
est
her
ema
ini
ngc
odei
nsi
deal
oopb
loc
ktob
eski
ppe
dan
dca
use
sex
ecu
tio
ntoj
umpt
o
t
het
opo
fthel
oopb
loc
k
Lo
op Us
eofCo
nti
nue!
!
fo
r
69
whi
le
d
o-whi
le
Go
tos
tat
eme
nt:
go
tol
abe
l;
l
abe
l:
Whe
nev
ergo
toke
ywo
rde
nco
unt
ere
dthe
nitc
aus
est
hep
rogr
amt
oco
nti
nueo
nthel
in
e,s
olo
nga
sit
i
sint
hes
cop
e.
Ty
peso
fGo
to
Fo
rwa
rdBa
ckwa
rd
7
0
UNI
T-2
ARRAYS
Wha
tisa
nar
ray
?
Ana
rra
yisac
oll
ect
io
nofs
imi
la
rda
tat
ypet
hata
reu
sedt
oal
lo
cat
eme
mor
yina
s
equ
ent
ialma
nne
r.
Sy
nta
x:<
dat
aty
pe>
<ar
rayn
ame
>[<
siz
eofa
nar
ray
>]
Su
bsc
rip
tori
nde
xin
g:As
ubs
cri
pti
spr
ope
rtyo
fana
rra
ytha
tdi
st
ingu
ishe
sal
lit
sst
ore
del
eme
nts
b
eca
usea
llt
hee
leme
ntsi
nana
rra
yha
vin
gthes
amen
ame(
i.
e.t
hea
rra
yna
me)
.sot
odi
st
ingu
ish
t
hes
e,weu
ses
ubs
cri
pti
ngo
rin
dex
ingo
pti
on.
e
.g.i
nta
r[20]
;
Fi
rste
leme
ntwi
llb
e:i
nta
r[0]
;
Se
con
del
eme
ntwi
llb
e:i
nta
r[1
];
Thi
rde
leme
ntwi
llb
e:i
nta
r[2]
;
Fo
urt
hel
eme
ntwi
llb
e:i
nta
r[3]
;
Fi
fthe
leme
ntwi
llb
e:i
nta
r[4
];
Si
xthe
leme
ntwi
llb
e:i
nta
r[5]
;
Soo
n……………………
La
ste
leme
ntwi
llb
e:i
nta
r[1
9];
7
1
· NOTE:Ana
rra
yal
way
sst
art
sfr
om0i
nde
xin
g.
· Ex
amp
le:i
nta
r[20]
;
Thi
sab
ovea
rra
ywi
lls
tor
e20i
nte
gert
ypev
alu
esfr
om0t
o19.
Ad
van
tageo
fana
rra
y:
· Mu
lti
pl
eel
eme
ntsa
res
tor
edu
nde
ras
ingl
eun
it.
· Se
arc
hin
gisfa
stb
eca
usea
llt
hee
leme
ntsa
res
tor
edi
nas
equ
enc
e.
Ty
peso
fAr
ray
1
. St
ati
cAr
ray
2. Dy
nami
cAr
ray
.
St
ati
cAr
ray
Ana
rra
ywi
thfi
xeds
izei
ssa
idt
obeas
tat
ica
rra
y.Ty
pes
o
fst
ati
car
ray
:
1
. On
eDi
men
sio
nal
Arr
ay
2. TwoDi
men
sio
nal
Arr
ay.
3. Mu
lti
Dime
nsi
ona
lAr
ray
.
1
. On
eDi
men
sio
nal
Arr
ay
AnAr
rayo
fel
eme
ntsi
sca
lle
d1d
ime
nsi
ona
l,whi
chs
tor
esd
atai
nco
lumno
rro
wfo
rm.
Ex
amp
le:i
nta
r[5]
;
Thi
sab
ovea
rra
yisc
all
edo
ned
ime
nsi
ona
lar
rayb
eca
usei
twi
lls
tor
eal
lthee
leme
ntsi
n
c
olu
mno
rinr
owfo
rm
2. TwoDi
men
sio
nal
Arr
ay.
Ana
rra
yofa
nar
rayi
ssa
idt
obe2d
ime
nsi
ona
lar
ray,whi
chs
tor
esd
atai
nco
lumna
ndr
owfo
rm
Ex
amp
le:i
nta
r[4
][5]
;
Thi
sab
ovea
rra
yisc
all
edt
wod
ime
nsi
ona
lar
rayb
eca
usei
twi
lls
tor
eal
lthee
leme
ntsi
nco
lumna
ndi
n
r
owfo
rm
NOTE:I
nab
ovee
xamp
leo
ftwod
ime
nsi
ona
lar
ray
,weha
ve4r
owsa
nd5c
olu
mns
.
NOTE:I
nab
ovee
xamp
leo
ftwod
ime
nsi
ona
lar
ray
,weha
vet
ota
lof20e
leme
nts
.
7
2
3. Mu
lti
Dime
nsi
ona
lAr
ray
.
Thi
sar
rayd
oesn
ote
xis
tinca
ndc
++.
Dy
nami
cAr
ray
.
Thi
sty
peo
far
raya
lsod
oesn
ote
xis
tinca
ndc
++.
Ex
amp
le:Pr
ogr
amb
ase
dup
ona
rra
y:
1
. #incl
ude
<st
dio
.h>
2. i
nt
main
()
{
3. i
n t
i
=0;
4.in t
marks [5];//decl
ara
tio
n o
f ar
ray
5. marks[0]= 80;//ini
ti
ali
zat
ion
of
arr
ay
6. marks[1
] =60;
7. marks[2] =70;
8. marks[3] =85;
9. marks[4]=7 5;
1
0.//t rave
r sal o
f array
1
1. for(
i=0; i
<5; i
++) {
1
2.p ri
ntf("%d \n",marks
[i]
);
1
3.} //end
o f for lo
op
1
4.r etu
rn 0;
1
5.}
Ex a
mp l
e:Pr ogramb asedupo
narra
y:
1
. #i nc
lude<
stdio
.h>
2. i
n t
main(
){
3. i
n t
i=
0;
4.in t
marks[5]={20,30,40,50,
60}
;//de
cla
rat
io
n a
nd
in
iti
al
iz
ati
on
of
arr
ay
5. //tr
avers
a l
of ar
r a
y
6. for(i
=0;i
<5; i
++){
7.p rin
tf("
%d \n"
, marks[
i])
;
8. }
9. retur
n 0;
1
0.}
7
3
STRI
NGS
Wha
tisSt
rin
g?
· As
tri
ngi
sac
oll
ect
io
nofc
har
act
ers
.
· As
tri
ngi
sal
soc
all
eda
sana
rra
yofc
har
act
ers
.
· ASt
rin
gmu
sta
cce
ssb
y%sa
cce
sss
pec
ifi
eri
nca
ndc
++.
· As
tri
ngi
sal
way
ste
rmi
nat
edwi
th\
0(Nu
ll)
cha
rac
ter
.
· Ex
amp
leo
fst
rin
g:―Ga
ura
v‖
· As
tri
nga
lwa
ysr
eco
gni
zedi
ndo
ubl
equ
ote
s.
· As
tri
nga
lsoc
ons
ide
rsp
acea
sac
har
act
er.
7
4
· Ex
amp
le:‖Ga
ura
vAr
ora
‖
· Thea
bov
est
rin
gco
nta
ins1
2cha
rac
ter
s.
· Ex
amp
le:Cha
rar
[20]
· Thea
bov
eex
amp
lewi
lls
tor
e19c
har
act
erwi
thIn
ull
cha
rac
ter
.
Ex
amp
le:Pr
ogr
amb
ase
dup
onSt
rin
g.
WAPt
oac
cep
tac
omp
let
est
rin
g(fi
rstn
amea
ndl
astn
ame
)an
ddi
spl
ayhe
ll
ome
ssa
gei
ntheo
utp
ut.
#incl
ude<st
dio.
h>
#in
clud
e<coni
o.h>
#in
clud
e<stri
ng.h>
voi
dma i
n()
{
charst
r1[20];charstr2[20]
;
pri
ntf(
"EnterFirstName")
;
sca
nf("
%s",&str1
);
pri
ntf(
"EnterlastName")
;
sca
nf("
%s",&str2);
put
s(st
r1)
;
put
s(st
r2);
}
St
rin
gFu
nct
io
nsi
nC:
Ou
rcl
angu
agep
rov
ide
susl
oto
fst
rin
gfu
nct
io
nsfo
rma
nip
ula
tin
gthes
tri
ng.
Al
lthes
tri
ngfu
nct
io
nsa
rea
vai
la
blei
nst
rin
g.hhe
ade
rfi
le
.
The
seSt
rin
gfu
nct
io
nsa
re:
1
. s
trl
en(
).
2. s
tru
pr(
).
3. s
trl
wr(
).
4
. s
trc
mp(
).
7
5
5. s
trc
at(
).
6
. s
trc
py(
).
7
. s
trr
ev(
).
1
.st
rle
n()
.
Thi
sst
rin
gfu
nct
io
nisb
asi
cal
lyu
sedfo
rthep
urp
oseo
fco
mpu
tin
gthee
ngt
hofs
tri
ng.
Ex
amp
le:c
hars
tr=
Gau
ravAr
ora
;
i
ntl
engt
h=s
trl
en(
str
);
p
rin
tf(
―The
len
gtho
fthes
tri
ngi
s=‖,
str
);
2.
str
upr
()
.
Thi
sst
rin
gfu
nct
io
nisb
asi
cal
lyu
sedfo
rthep
urp
oseo
fco
nve
rti
ngt
hec
ases
ens
it
ive
nes
soft
he
s
tri
ngi
.e.i
tco
nve
rtss
tri
ngc
ases
ens
it
ive
nes
sin
tou
ppe
rca
se.
Ex
amp
le:c
hars
tr=
―ga
ura
v‖
s
tru
pr(
str
);
p
rin
tf(
―The
upp
erc
ase
oft
hes
tri
ngi
s:%s
‖,s
tr)
;
3.s
trl
wr(
).
Thi
sst
rin
gfu
nct
io
nisb
asi
cal
lyu
sedfo
rthep
urp
oseo
fco
nve
rti
ngt
hec
ases
ens
it
ive
nes
soft
he
s
tri
ngi
.ei
tco
nve
rtss
tri
ngc
ases
ens
it
ive
nes
sin
tol
owe
rca
se.
Ex
amp
le:c
hars
tr=
―ga
ura
v‖
s
trl
wr(
str
);
p
rin
tf(
―The
Lowe
rca
seo
fthe
str
ingi
s:%s‖,
str
);
4
.st
rcmp
().
Thi
sst
rin
gfu
nct
io
nisb
asi
cal
lyu
sedfo
rthep
urp
oseo
fco
mpa
rin
gtwos
tri
ng.
Thi
sst
rin
gfu
nct
io
nco
mpa
rest
wos
tri
ngsc
har
act
erb
ycha
rac
ter
s.
Thu
sitgi
vesr
esu
lti
nthr
eec
ase
s:
Ca
se1
:iffi
rsts
tri
ng>t
hans
eco
nds
tri
ngt
hen
,re
sul
twi
llb
etr
ue.
7
6
Ca
se2:i
ffi
rsts
tri
ng<t
hans
eco
nds
tri
ngt
hen
,re
sul
twi
llb
efa
lse
.
Ca
se3:i
ffi
rsts
tri
ng==t
ose
con
dst
rin
gthe
n,r
esu
ltwi
llb
eze
ro.
Ex
amp
le:
c
har
s
tr1
=―Ga
ura
v‖;
cha
r
s
tr2=
―Ar
ora
‖;
c
hars
tr3=
str
cmp
(st
r1,
str
2);
p
rin
tf(
―%s‖,
str
3);
5.s
trc
at(
).
Thi
sst
rin
gfu
nct
io
nisu
sedfo
rthep
urp
oseo
fco
nca
ten
ati
ngt
wos
tri
ngsi
e.(
mer
gin
gtwoo
rmo
re
s
tri
ngs
)
Ex
amp
le:
c
hars
tr1=―Ga
ura
v‖;
c
hars
tr2=―Ar
ora
‖;
c
hars
tr3[
30]
;
s
tr3=
str
cat
(st
r1,
str
2);
p
rin
tf(
―%s‖,
str
3);
6
.st
rcp
y()
Thi
sst
rin
gfu
nct
io
nisb
asi
cal
lyu
sedfo
rthep
urp
oseo
fco
pyi
ngo
nes
tri
ngi
ntoa
not
hers
tri
ng.c
har
s
tr1
=―Ga
ura
v‖;
c
hars
tr2[
20]
;
s
tr2=s
trc
py(
str
2,s
tr1
);
p
rin
tf(
―%s‖,
str
2);
6.s
trr
ev(
)
Thi
sst
rin
gfu
nct
io
nisb
asi
cal
lyu
sedfo
rthep
urp
oseo
fre
ver
sin
gthes
tri
ng.
c
hars
tr1
=―Ga
ura
v‖;
c
hars
tr2[
20]
;
7
7
s
tr2=s
trr
ev(
str
2,s
tr1
);
p
rin
tf(
―%s‖,
str
2);
Ex
amp
le:Pr
ogr
amb
ase
dup
ons
tri
ngfu
nct
io
ns.
WAPt
oac
cep
tas
tri
nga
ndp
erfo
rmv
ari
ouso
per
ati
ons
:
1
.Toc
onv
erts
tri
ngi
ntou
ppe
rca
se.
2.Tor
eve
rset
hes
tri
ng.
3.Toc
opys
tri
ngi
ntoa
not
her
str
ing.
4
.Toc
omp
utel
engt
hde
pen
din
gup
onu
ser
cho
ice
.
#i nc
lude<st
dio.
h>
#i nc
lude<con
io.h>
#includ
e<stri
ng.h>
voidmain()
{
chars t
r[20];
chars t
r1[20];
i
n topt,l
en;
printf(
"\nMAI NMENU" );
printf(
"\n1.Con v
ertst
ringin
touppercase
")
;
printf(
"\n2.Re vers
ethestri
ng")
;
printf(
"\n3.Co pyonest
r i
ngint
oanotherst
rin
g")
;
printf(
"\n4.Comp ut
elengthofstr
ing");
printf(
"\nEnterstri
ng");
scanf("
%s",&s t
r )
;
printf(
"Enteryourchoi
ce")
;
scanf("
%d",&opt);
switch(
opt)
{
case1:
strupr(
str);
printf(
"Thes t
ringinupper
casei
s:%s" ,
str)
;
break;
case2:
strrev(
str);
printf(
"Ther e
verseofstri
ngis:%s",st
r);
break;
case3:
strcpy(
str1,
str)
;
printf(
"Newc opi
edstri
ngis:%s",st
r1)
;
break;
case4 :
7
8
l
en=
s t
rlen(
str
);
p
rin
tf("Thelen
gthofthes
tri
ngis:%s",l
en)
;
b
reak;
d
efault
:
p
rin
tf("Ypuhaveen
ter
edawrongcho
ice
.")
;
}
}
7
9
UNI
T-I
I
IFUNCTI
ONSAND
POI
NTERS
FUNCTI
ONS
Afu
nct
io
nisi
ts
elfab
loc
kofc
odewhi
chc
ans
olv
esi
mpl
eorc
omp
lext
ask/c
alc
ula
tio
ns.
Afu
nct
io
npe
rfo
rmsc
alc
ula
tio
nso
nthed
atap
rov
ide
dtoi
tisc
all
ed"
par
ame
ter
"or"
argu
men
t".A
fu
nct
io
nal
way
sre
tur
nss
ingl
eva
luer
esu
lt.
Ty
peso
ffu
nct
io
n:
1
.Bu
il
tinfu
nct
io
ns(
Lib
rar
yfu
nct
io
ns)
a
.)I
npu
tti
ngFu
nct
io
ns.
b
.)Ou
tpu
tti
ngfu
nct
io
ns.
2.Us
erd
efi
ned
fun
cti
ons
.
a
.)fa
ct(
);
b
.)s
um(
);
Pa
rtso
fafu
nct
io
n:
1
.Fu
nct
io
nde
cla
rat
io
n/Pr
oto
typ
e/Sy
nta
x.
2.Fu
nct
io
nCa
lli
ng.
3.Fu
nct
io
nDe
fin
iti
on.
1
.)
Fun
cti
onDe
cla
rat
io
n:
Sy
nta
x:<
ret
urnt
ype>
<fu
nct
io
nna
me>
(<t
ypeo
far
gume
nt>
)
Thed
ecl
ara
tio
noffu
nct
io
nna
me,i
tsa
rgu
men
tan
dre
tur
nty
pei
sca
lle
dfu
nct
io
nde
cla
rat
io
n.
2.
)Fu
nct
io
nCa
lli
ng:
Thep
roc
esso
fca
lli
ngafu
nct
io
nfo
rpr
oce
ssi
ngi
sca
lle
dfu
nct
io
nca
lli
ng.
Sy
nta
x:<
var
_na
me>
=<fu
nct
io
n_n
ame
>(<
li
sto
far
gume
nts
>).
3.
)Fu
nct
io
nde
fin
ati
on:
80
Thep
roc
esso
fwr
iti
ngac
odefo
rpe
rfo
rmi
nga
nys
pec
ifi
cta
ski
sca
lle
dfu
nct
io
nde
fin
ati
on.
Sy
nta
x:
<
ret
urnt
ype
><fu
nct
io
nna
me>
(<t
ypeo
far
gume
nts
>)
{
<
sta
teme
nt-
1>
<
sta
teme
nt-
2>
r
etu
rn(
<vl
aue
>)
}
Ex
amp
le:p
rogr
amb
ase
dup
onfu
nct
io
n:
WAPt
oco
mpu
tec
ubeo
fan
o.u
sin
gfu
nct
io
n.#i
ncl
ude
<st
dio
.h>
#i
ncl
ude
<co
nio
.h>v
oid
ma
in(
)
{
i
ntc
,n;
i
ntc
ube
(i
nt)
;
p
rin
tf(
"En
teran
o."
);
s
can
f("
%d"
,&n
);
c
=cu
be(
n)
;
p
rin
tf(
"c
ubeo
fan
o.i
s=%d
",c
);
}
i
ntc
ube
(i
ntn
)
{
c
=n*
n*n
;
r
etu
rn(
c)
;
}
WAPt
oco
mpu
tefa
cto
ria
lofan
o.u
sin
gfu
nct
io
n:
#i
ncl
ude
<st
dio
.h>
#i
ncl
ude
<co
nio
.h>v
oid
ma
in(
)
81
{
i
ntn
,f=
1;
i
ntfa
ct(
in
t)
p
rin
tf(
"En
teran
o."
);
s
can
f("
%d"
,&n
);
f=
fac
t(n
);
p
rin
tf(
"Thefa
cto
ria
lofan
o.i
s:=
%d"
,f)
;
}
i
ntfa
ct(
in
tn)
i
ntf=
1;
{
fo
r(i
nti
=n;
i>=
n;i
--)
{
f=
f*i
;
}
r
etu
rn(
f);
}
Re
cur
sio
n
Fi
rst
ly,wha
tisn
est
edfu
nct
io
n?
Whe
nafu
nct
io
nin
voke
san
othe
rfu
nct
io
nthe
niti
sca
lle
dne
ste
dfu
nct
io
n.
Bu
t,
Whe
nafu
nct
io
nin
voke
sit
sel
fthe
niti
sca
lle
dre
cur
sio
n.
NOTE:I
nre
cur
sio
n,wemu
sti
ncl
udeat
ermi
nat
ingc
ond
iti
ons
otha
titwo
n'
tex
ecu
tet
oin
fin
itet
ime
.
Ex
amp
le:p
rogr
amb
ase
dup
onr
ecu
rsi
on:
WAPt
oco
mpu
tefa
cto
ria
lofan
o.u
sin
gRe
cur
sio
n:
#i
ncl
ude
<st
dio
.h>
#i
ncl
ude
<co
nio
.h>v
oid
ma
in(
)
82
{
i
ntn
,f;
i
ntfa
ct(
in
t)
p
rin
tf(
"En
teran
o."
);
s
can
f("
%d"
,&n
);
f=
fac
t(n
);
p
rin
tf(
"Thefa
cto
ria
lofan
o.i
s:=
%d"
,f)
;
}
i
ntfa
ct(
in
tn)
i
ntf=
1;
{
i
f(n
=0)
r
etu
rn(
f);
e
lse
r
etu
rn(
n*fa
ct(
n-1
))
;
}
Pa
ssi
ngp
ara
met
erst
oafu
nct
io
n:
Fi
rst
ly,wha
tar
epa
rame
ter
s?
p
ara
met
ersa
ret
hev
alu
est
hata
rep
ass
edt
oafu
nct
io
nfo
rpr
oce
ssi
ng.
The
rea
re2t
ype
sofp
ara
met
ers
:
a
.)Ac
tua
lPa
rame
ter
s.
b
.)Fo
rma
lPa
rame
ter
s.
a
.)Ac
tua
lPa
rame
ter
s:
The
sea
ret
hep
ara
met
erswhi
cha
reu
sedi
nma
in(
)fu
nct
io
nfo
rfu
nct
io
nca
lli
ng.
Sy
nta
x:<
var
iab
len
ame
>=<
fun
cti
onn
ame
><a
ctu
ala
rgu
men
t>
Ex
amp
le:f=
fac
t(n
);
b
.)Fo
rma
lPa
rame
ter
s.
The
sea
ret
hep
ara
met
erswhi
cha
reu
sedi
nfu
nct
io
nde
fin
ati
onfo
rpr
oce
ssi
ng.
83
Me
tho
dso
fpa
rame
ter
spa
ssi
ng:
1
.)Ca
llb
yre
fer
enc
e.
2.
)Ca
llb
yva
lue
.
1
.)Ca
llb
yre
fer
enc
e:
I
nthi
sme
tho
dofp
ara
met
erp
ass
ing,o
rigi
nalv
alu
eso
fva
ria
ble
sar
epa
sse
dfr
omc
all
in
g
p
rogr
amt
ofu
nct
io
n.
Thu
s,
An
ycha
ngema
dei
nthefu
nct
io
nca
nber
efl
ect
edb
ackt
othec
all
in
gpr
ogr
am.
2.
)Ca
llb
yva
lue
.
I
nthi
sme
tho
dofp
ara
met
erp
ass
ing,d
upl
ic
atev
alu
eso
fpa
rame
ter
sar
epa
sse
dfr
omc
all
in
gpr
ogr
am
t
ofu
nct
io
nde
fin
ati
on.
Thu
s,
An
ycha
ngema
dei
nfu
nct
io
nwo
uldn
otb
ere
fle
cte
dba
ckt
othec
all
in
gpr
ogr
am.
Ex
amp
le:Pr
ogr
amb
ase
dup
onc
allb
yva
lue
:#
i
ncl
ude
<st
dio
.h>
#i
ncl
ude
<co
nio
.h>
v
oidma
in(
)
{
i
nta
,b;
a
=10;
b
=20;
v
oids
wap
(i
nt,
int
)
p
rin
tf(
"Thev
alu
eofab
efo
res
wap
pin
g=%d
",a
);
p
rin
tf(
"Thev
alu
eofbb
efo
res
wap
pin
g=%d
",b
);
v
oid
swa
p(a
,b)
;
p
rin
tf(
"Thev
alu
eofaa
fte
rswa
ppi
ng=
%d"
,a)
;
p
rin
tf(
"Thev
alu
eofba
fte
rswa
ppi
ng=
%d"
,b)
;
84
}
v
oids
wap
(i
ntx
,in
ty)
{
i
ntt
;
t
=x;
x
=y;
y
=t;
}
STORAGECLASSES
Ev
eryVa
ria
blei
nap
rogr
amha
sme
mor
yas
soc
iat
edwi
thi
t.
Me
mor
yRe
qui
reme
nto
fVa
ria
ble
sisd
iffe
ren
tfo
rdi
ffe
ren
tty
peso
fva
ria
ble
s.I
n
C,Me
mor
yisa
llo
cat
ed&r
ele
ase
datd
iffe
ren
tpl
ace
s
Te
rm De
fin
iti
on
Sc
ope Re
gio
norPa
rto
fPr
ogr
ami
nwhi
chVa
ria
blei
sac
ces
si
ble
Ex
ten
t Pe
rio
doft
imed
uri
ngwhi
chme
mor
yisa
sso
cia
tedwi
thv
ari
abl
e
St
ora
ge Ma
nne
rinwhi
chme
mor
yisa
llo
cat
edb
ytheCo
mpi
le
rfo
rVa
ria
ble
Cl
ass Di
ffe
ren
tSt
ora
geCl
ass
es
St
ora
gec
las
sofv
ari
abl
eDe
ter
min
esfo
llo
win
gthi
ngs
Whe
ret
hev
ari
abl
eiss
tor
ed
Sc
opeo
fVa
ria
ble
De
fau
lti
ni
ti
alv
alu
e
Li
fet
imeo
fva
ria
ble
A.Wh
ere
the
var
ia
ble
is
st
ore
d:
St
ora
geCl
ass
det
ermi
nest
hel
oca
tio
nofv
ari
abl
e,whe
rei
tisd
ecl
are
d.Va
ria
ble
sde
cla
redwi
tha
uto
s
tor
agec
las
sesa
red
ecl
are
din
sid
ema
inme
mor
ywhe
rea
sva
ria
ble
sde
cla
redwi
thke
ywo
rdr
egi
st
era
re
s
tor
edi
nsi
det
heCPURe
gis
ter
.
85
B.
Sco
peo
fVa
ri
ab
le
Sc
opeo
fVa
ria
blet
ell
sco
mpi
lea
bou
tthev
isi
bi
li
tyo
fVa
ria
blei
ntheb
loc
k.Va
ria
blema
yha
ve
Bl
ockSc
ope
,Lo
calSc
opea
ndEx
ter
nalSc
ope
.As
cop
eist
hec
ont
extwi
thi
nac
omp
ute
rpr
ogr
ami
n
whi
chav
ari
abl
ena
meo
rot
heri
den
tifi
eri
sva
li
dan
dca
nbeu
sed
,orwi
thi
nwhi
chad
ecl
ara
tio
nha
s
e
ffe
ct.
C.De
fau
lt
In
it
ia
lVa
lue
oft
heVa
ri
ab
le
Whe
nev
erwed
ecl
areaVa
ria
blei
nC,ga
rba
gev
alu
eisa
ssi
gne
dtot
hev
ari
abl
e.Ga
rba
geVa
lue
ma
ybec
ons
ide
reda
sin
iti
alv
alu
eoft
hev
ari
abl
e.CPr
ogr
ammi
ngha
ved
iffe
ren
t
s
tor
age
cla
sse
swhi
chha
sdi
ffe
ren
tin
iti
alv
alu
ess
ucha
sGl
oba
lVa
ria
bleha
veI
ni
ti
alVa
luea
s0
whi
let
heLo
cala
utov
ari
abl
eha
ved
efa
ulti
ni
ti
alga
rba
gev
alu
e.
D.L
ife
ti
meo
fva
ri
ab
le
Li
fet
imeo
fthe=Ti
meOfv
ari
abl
eDe
cla
rat
io
n-Ti
meo
fVa
ria
bleDe
str
uct
io
n
Su
ppo
seweha
ved
ecl
are
dva
ria
blei
nsi
dema
infu
nct
io
nthe
nva
ria
blewi
llb
ede
str
oye
don
lywhe
n
t
hec
ont
rolc
ome
sou
toft
hema
in.
i.ee
ndo
fthep
rogr
am.
Di
ffe
ren
tSt
ora
geCl
as
se
s:
Au
toSt
ora
geCl
ass
St
ati
cSt
ora
geCl
ass
Ex
ter
nSt
ora
ge
Cl
ass
Regi
st
erSt
ora
ge
Cl
ass
Au
toma
tic(
Aut
o)s
tor
agec
las
s
Thi
sisd
efa
ults
tor
agec
las
s
Al
lva
ria
ble
sde
cla
reda
reo
fty
peAu
tob
yde
fau
lt
I
nor
dert
oEx
pli
ci
tde
cla
rat
io
nofv
ari
abl
eus
e‗a
uto
‘ke
ywo
rda
uto
i
ntn
um1;//Ex
pli
ci
tDe
cla
rat
io
n
Fe
atu
res
:
St
ora
ge Me
mor
y
86
Sc
ope Lo
cal/Bl
ockSc
ope
87
Li
fet
ime Ex
ist
sasl
onga
sCo
ntr
olr
ema
insi
nthe
b
loc
k
De
fau
lti
ni
ti
al Ga
rba
ge
Va
lue
Ex
amp
le
v
oidmain(
)
{
automum=20;
{
aut
onum=60;
pri
ntf(
"nNu
m:%d",n
um)
;
}
pri
n t
f("
nNum:%d "
,nu
m);
}
Ou
tpu
t:
Nu
m:60
Nu
m:20
No
te:
Twov
ari
abl
esa
red
ecl
are
dind
iffe
ren
tbl
ocks,s
othe
yar
etr
eat
eda
sdi
ffe
ren
tva
ria
ble
s
Ex
ter
nal(e
xte
rn)s
tor
agec
las
sinCPr
ogr
ammi
ng
Va
ria
ble
soft
hiss
tor
age
cla
ssa
re―Gl
oba
lva
ria
ble
s‖
Gl
oba
lVa
ria
ble
sar
ede
cla
redo
uts
idet
hefu
nct
io
nan
dar
eac
ces
si
blet
oal
lfu
nct
io
nsi
nthep
rogr
am
Ge
ner
all
y,Ex
ter
nalv
ari
abl
esa
red
ecl
are
daga
ini
nthefu
nct
io
nus
ingke
ywo
rde
xte
rnI
n
o
rde
rtoEx
pli
ci
tde
cla
rat
io
nofv
ari
abl
eus
e‗e
xte
rn‘ke
ywo
rd
e
xte
rni
ntn
um1;//Ex
pli
ci
tDe
cla
rat
io
n
Fe
atu
res:
88
St
ora
ge Me
mor
y
Sc
ope Gl
oba
l/Fi
leSc
ope
Li
fet
ime Ex
ist
sasl
onga
sva
ria
blei
sru
nni
ng
Re
tai
nsv
alu
ewi
thi
nthefu
nct
io
n
De
fau
lti
ni
ti
alVa
lue Ze
ro
Ex
amp
le
i
ntn
um=7
5;
v
oidd
isp
lay
()
;
v
oidmain(
)
{
exte
rnintnu
m;
pri
ntf(
"nNu
m:%d
",n
um)
;
di
splay
()
;
}
v
oiddi
spl
ay(
)
{
exte
rnin
tnum;
pr
int
f("
nNu
m:%d
",n
um)
;
}
Ou
tpu
t:
Nu
m:7
5
Nu
m:7
5
No
te:
De
cla
rat
io
nwi
thi
nthefu
nct
io
nin
dic
ate
stha
tthefu
nct
io
nus
ese
xte
rna
lva
ria
ble
Fu
nct
io
nsb
elo
ngi
ngt
osa
mes
our
cec
ode,d
oesn
otr
equ
ired
ecl
ara
tio
n(n
one
edt
owr
itee
xte
rn)I
f
v
ari
abl
eisd
efi
nedo
uts
idet
hes
our
cec
ode,t
hend
ecl
ara
tio
nus
inge
xte
rnke
ywo
rdi
sre
qui
red
St
ati
cSt
ora
geCl
ass
89
Thes
tat
ics
tor
agec
las
sin
str
uct
sthec
omp
il
ert
oke
epal
oca
lva
ria
blei
nex
ist
enc
edu
rin
gthel
ife
-
t
imeo
fthep
rogr
ami
nst
eado
fcr
eat
inga
ndd
est
roy
ingi
tea
cht
imei
tco
mesi
ntoa
ndgo
eso
uto
f
s
cop
e.The
refo
re,ma
kin
glo
calv
ari
abl
ess
tat
ica
llo
wst
hemt
oma
int
aint
hei
rva
lue
sbe
twe
en
fu
nct
io
nca
lls
.
Thes
tat
icmo
difi
erma
yal
sob
eap
pli
edt
ogl
oba
lva
ria
ble
s.Whe
nthi
sisd
one
,itc
aus
est
hat
v
ari
abl
e'
ssc
opet
ober
est
ric
tedt
othefi
lei
nwhi
chi
tisd
ecl
are
d.
I
nCp
rogr
ammi
ng,whe
nst
ati
cisu
sedo
nac
las
sda
tame
mbe
r,i
tca
use
son
lyo
nec
opyo
ftha
t
me
mbe
rtob
esha
redb
yal
ltheo
bje
ctso
fit
scl
ass
.
#i
ncl
ude<
std
io.
h>
/*fun
cti
ondec
lar
ati
on*
/
voi
dfunc
(vo
id)
;
s
tat
ici
ntc
oun
t=5;/*gl
oba
lva
ria
ble*
/
ma
in(
){
whi
le
(co
unt
--)
{func
()
;
}
re
tur
n0;
}
/*fun
cti
ond
efin
iti
on*
/
voi
dfunc
(vo
id){
s
tat
ici
nti
=5;/*l
oca
lst
ati
cva
ria
ble*
/
i
++;
pr
int
f("
iis%da
ndc
oun
tis%d
\n"
,i,c
oun
t);
}
Whe
nthea
bov
eco
dei
sco
mpi
le
dan
dex
ecu
ted
,itp
rod
uce
sthefo
ll
owi
ngr
esu
lt−ii
s
6a
ndc
oun
tis4
ii
s7a
ndc
oun
tis3i
i
s8a
ndc
oun
tis2ii
s
9a
ndc
oun
tis1ii
s10
a
ndc
oun
tis
0
90
Re
gis
terSt
ora
geCl
ass
r
egi
st
erke
ywo
rdi
sus
edt
ode
fin
elo
calv
ari
abl
e.Lo
cal
v
ari
abl
ear
est
ore
dinr
egi
st
eri
nst
eado
fRAM.
Asv
ari
abl
eiss
tor
edi
nre
gis
ter
,theMa
ximu
msi
zeo
fva
ria
ble=Ma
ximu
mSi
zeo
fRe
gis
teru
nar
y
o
per
ato
r[&]i
sno
tas
soc
iat
edwi
thi
tbe
cau
seVa
luei
sno
tst
ore
dinRAMi
nst
eadi
tiss
tor
edi
n
Re
gis
ter
.
Thi
sisge
ner
all
yus
edfo
rfa
ste
rac
ces
s.
Co
mmo
nus
eis―Co
unt
er―
Synt
ax
{
re
gist
erin
tcount
;
}
Regi
ste
rstora
gecla
sse
sex
amp
le
#i
ncl
ude<s
tdi
o.h>
i
ntmai
n()
{
i
ntnu
m1,num2;
r
egi
steri
ntsum;
p
rin
t f(
"\
nEnt
ertheNu
mbe
r1:"
);
s
canf("
%d"
,&num1
);
p
rin
t f(
"\
nEnt
ertheNu
mbe
r2:"
);
s
canf("
%d"
,&num2)
;
s
um=n
um1+n
um2;
p
rin
tf(
"\
nSu
mofNu
mbe
rs:%d
",s
um)
;
re
turn(
0);
}
Expl
anat
iono
fpr
ogr
am
Re
ferb
elo
wan
ima
tio
nwhi
chd
epi
ct
sther
egi
st
ers
tor
agec
las
ses–
91
I
nthea
bov
epr
ogr
amweha
ved
ecl
are
dtwov
ari
abl
esn
um1
,nu
m2.The
set
wov
ari
abl
esa
res
tor
edi
n
RAM.
An
othe
rva
ria
blei
sde
cla
redwhi
chi
sst
ore
dinr
egi
st
erv
ari
abl
e.Re
gis
terv
ari
abl
esa
res
tor
edi
nthe
r
egi
st
ero
fthemi
cro
pro
ces
sor
.Thu
sme
mor
yac
ces
swi
llb
efa
ste
rtha
not
herv
ari
abl
es.
I
fwet
ryt
ode
cla
remo
rer
egi
st
erv
ari
abl
est
heni
tca
ntr
eatv
ari
abl
esa
sAu
tos
tor
agev
ari
abl
esa
s
me
mor
yofmi
cro
pro
ces
sori
sfi
xeda
ndl
imi
te
d.
Whywen
eedRe
gis
terVa
ria
ble?
Whe
nev
erwed
ecl
area
nyv
ari
abl
ein
sid
eCPr
ogr
amt
henme
mor
ywi
llb
era
ndo
mlya
llo
cat
eda
t
p
art
ic
ula
rme
mor
ylo
cat
io
n.
Weha
vet
oke
ept
rac
koft
hatme
mor
ylo
cat
io
n.Wen
eedt
oac
ces
sva
luea
ttha
tme
mor
ylo
cat
io
nus
ing
a
mpe
rsa
ndo
per
ato
r/Ad
dre
ssOp
era
tor
i.e(
&).
I
fwes
tor
esa
mev
ari
abl
eint
her
egi
st
erme
mor
ythe
nwec
ana
cce
sst
hatme
mor
ylo
cat
io
ndi
rec
tly
wi
tho
utu
sin
gtheAd
dre
sso
per
ato
r.
Re
gis
terv
ari
abl
ewi
llb
eac
ces
sedfa
ste
rtha
nthen
orma
lva
ria
blet
husi
ncr
eas
ingt
heo
per
ati
on
a
ndp
rogr
ame
xec
uti
on.Ge
ner
all
yweu
ser
egi
st
erv
ari
abl
easCo
unt
er.
No
te:I
tisn
ota
ppl
ic
abl
efo
rar
ray
s,s
tru
ctu
reso
rpo
int
ers
.
Su
mma
ryo
fre
gis
terSt
ora
gec
las
s
Ke
ywo
rd r
egi
st
er
St
ora
geLo
cat
io
n CPURe
gis
ter
92
Ke
ywo
rd r
egi
st
er
I
ni
ti
alVa
lue Ga
rba
ge
Li
fe Lo
calt
otheb
loc
kinwhi
chv
ari
abl
eisd
ecl
are
d.
Sc
ope Lo
calt
otheb
loc
k.
Pr
epr
oce
sso
rdi
rec
tiv
es
Be
for
eaCp
rogr
ami
sco
mpi
le
dinac
omp
il
er,s
our
cec
odei
spr
oce
sse
dbyap
rogr
amc
all
ed
p
rep
roc
ess
or.Thi
spr
oce
ssi
sca
lle
dpr
epr
oce
ssi
ng.
Co
mma
ndsu
sedi
npr
epr
oce
sso
rar
eca
lle
dpr
epr
oce
sso
rdi
rec
ti
vesa
ndt
heyb
egi
nwi
th―#‖s
ymb
ol.
Be
lowi
sthel
is
tofp
rep
roc
ess
ord
ire
cti
vest
hatCl
angu
ageo
ffe
rs.
S.
no Pr
epr
oce
sso
r Sy
nta
x De
scr
ipt
ion
Thi
sma
crod
efi
nes
c
ons
tan
tva
luea
nd
c
anb
ean
yoft
he
1 Ma
cro #d
efi
ne b
asi
cda
tat
ype
s.
Thes
our
cec
odeo
f
t
hefi
le―fi
le
_na
me‖
i
sin
clu
dedi
nthe
He
ade
rfi
le #i
ncl
ude ma
inp
rogr
ama
tthe
2 i
ncl
usi
on <
fil
e_n
ame
> s
pec
ifi
edp
lac
e
Se
tofc
omma
ndsa
re
i
ncl
ude
dore
xcl
ude
din
#i
fde
f,#e
ndi
f, s
our
cep
rogr
am
Co
ndi
ti
ona
l #i
f, b
efo
rec
omp
il
ati
on
3 c
omp
il
ati
on #e
lse
,#i
fnd
ef wi
thr
esp
ectt
othe
93
c
ond
iti
on
#u
nde
fisu
sedt
o
u
nde
fin
ead
efi
ned
ma
crov
ari
abl
e.
#Pr
agmai
sus
edt
o
c
allafu
nct
io
nbe
for
e
a
nda
fte
rma
in
Ot
her fu
nct
io
ninaC
4 d
ire
cti
ves #u
nde
f,#p
ragma p
rogr
am
Ap
rogr
ami
nCl
angu
agei
nvo
lve
sin
tod
iffe
ren
tpr
oce
sse
s.Be
lowd
iagr
amwi
llhe
lpy
out
oun
der
sta
nd
a
llt
hep
roc
ess
est
hataCp
rogr
amc
ome
sac
ros
s.
EXAMPLEPROGRAMFOR#DEFI
NE,#I
NCLUDEPREPROCESSORSI
NC:
#d
efi
ne–Thisma c
rodefi
nescons
tan
tvalu
eandcanbean
yoftheba
sicd
atat
ype
s.
#i
ncl
ude<
fil
e_name>
– Thes ou
rcecod
eofthefil
e―fi
le
_name
‖isi
ncl
ude
dint
hemai
nC
pr
ogramwhere―#i
ncl
ude<fil
e_name
>‖isment
io
ned.
#i
ncl
ude<
std
io.
h>
#d
efi
nehei
ght100
#d
efi
nenumber3.1
4
#d
efi
nele
tte
r'A'
#d
efi
nele
tte
r_sequ
enc
e"ABC"
#d
efi
neback
slas
h_char'
\?'
v
oidmain
()
{
pri
ntf(
"va
lueofhei
ght:%d\ n"
,he i
ght);
pri
ntf(
"va
lueo
fn u
mb e
r:%f\ n"
,number);
pri
ntf(
"va
lueo
flet
ter:%c\ n"
,lett
er);
pri
ntf(
"va
lueofle
tte
r_sequ
ence:%s\ n",l
ett
er_seq
uen
ce)
;
pri
ntf(
"va
lueo
fbacksl
ash_char:%c\n",ba
cksl
ash_cha
r);
}OUTPUT:
94
v
alu
eofhe
ight:1
00
v
alu
eofn
umb
er:3.
140000
v
alu
eofl
ett
er:A
v
alu
eofl
ett
er_s
equ
enc
e:ABC
v
alu
eofb
acks
las
h_c
har:?
EXAMPLEPROGRAMFORCONDI
TIONALCOMPI
LATI
ONDI
RECTI
VES:
A) EXAMPLEPROGRAMFOR#I
FDEF,#ELSEAND#ENDI
FINC:
―#i
fde
f‖d
ire
cti
vec
hec
kswhe
the
rpa
rti
cul
arma
croi
sde
fin
edo
rno
t.I
fiti
sde
fin
ed,―I
f‖c
lau
se
s
tat
eme
ntsa
rei
ncl
ude
dins
our
cefi
le
.
Ot
her
wis
e,―e
ls
e‖c
lau
ses
tat
eme
ntsa
rei
ncl
ude
dins
our
cef
ile
for
comp
il
ati
ona
nde
xec
uti
on.
#i
ncl
ude<
std
io.
h>
#d
efi
neRAJU100
i
ntmain(
)
{
#ifde
fRAJU
prin
tf(
"RAJUi
sd e
fine
d.So,thi
sli
newi
llb
ead
dedi
n"\
"
thi
sCfil
e\n
");
#els
e
prin
tf(
"RAJUi
sn o
tdefin
ed\
n")
;
#endi
f
retu
rn0;
}
OUTPUT:
RAJUi
sde
fin
ed.So
,thi
sli
newi
llb
ead
dedi
nthi
sCfi
le
B)EXAMPLEPROGRAMFOR#I
FNDEFAND#ENDI
FINC:
#i
fnd
efe
xac
tlya
cts
asr
eve
rsea
s#i
fde
fdi
rec
ti
ve.I
fpa
rti
cul
arma
croi
sno
tde
fin
ed,―I
f‖c
lau
ses
tat
eme
nts
a
rei
ncl
ude
dins
our
cefi
le
.
Ot
her
wis
e,e
lsec
lau
ses
tat
eme
ntsa
rei
ncl
ude
dins
our
cefi
lefo
rco
mpi
la
tio
nan
dex
ecu
tio
n.
#i
ncl
ude<
std
io.
h>
#d
efi
neRAJU100
95
i
ntmai
n (
)
{
#i
fndefSELVA
{
pri
n t
f("
SELVAisnotdefi
ned
.So,nowwear
egoin
gto"\
"d
efin
ehe
re\n
");
#defin
eSELVA300
}
#el
se
pri
ntf(
"SELVAi
salread
yd e
fine
dint
hepro
gram‖
);
#e
ndi
f
re
tur
n0;
}OUTPUT:
SELVAi
sno
tde
fin
ed.So
,no
wwea
rego
ingt
ode
fin
ehe
re
C) EXAMPLEPROGRAMFOR#I
F,#ELSEAND#ENDI
FINC:
―I
f‖c
lau
ses
tat
eme
nti
sin
clu
dedi
nso
urc
efi
lei
fgi
ven
con
dit
io
nis
tru
e.
Ot
her
wis
e,e
lsec
lau
ses
tat
eme
nti
sin
clu
dedi
nso
urc
efi
lefo
rco
mpi
la
tio
nan
dex
ecu
tio
n.
#i
ncl
ude<stdi
o.h>
#d
efin
ea1 00
i
ntmain(
)
{
#i
f(a =
=100)
pri
ntf(
"Thisli
newil
lbeadde
dint
hisCfi
les
inc
e"\"
a
\=100\n"
);
#el
se
pri
ntf(
"Thisli
newil
lbeadde
dint
hisCfi
les
inc
e"\"
a
isnotequalt
o100\
n")
;
#end
if
ret
urn0;
}
OUTPUT:
Thi
sli
newi
llb
ead
dedi
nthi
sCfi
les
inc
ea=1
00
96
EXAMPLEPROGRAMFORUNDEFI
NC:
Thi
sdi
rec
ti
veu
nde
fin
ese
xis
ti
ngma
croi
nthep
rogr
am.
#i
ncl
ude<
std
io.
h>
#de
finehe i
ght100
vo
idmain()
{
pri
ntf("Firs
tdefi
nedval
uefor
height :%d \n"
,he
ight)
;
#undefheight //unde
fini
ngvari
abl
e
#defi
n e
height600 //r edefi
ningthes
amefornewvalu
e
pri
ntf("valu
eofhei
ghta ft
eru n
def\&red
efi
ne:
%d",he
ight)
;
}
OUTPUT:
Fi
rstd
efi
nedv
alu
efo
rhe
ight:1
00
v
alu
eofhe
ighta
fte
run
def&r
ede
fin
e:600
EXAMPLEPROGRAMFORPRAGMAI
NC:
Pr
agmai
sus
edt
oca
llafu
nct
io
nbe
for
ean
daft
erma
infu
nct
io
ninaCp
rogr
am.
#i
ncl
ude<
std
io.
h>
v
oidfu
nct
io
n1()
;
v
oidfu
nct
io
n2();
#p
ragmas
tart
upfunct
io
n1
#p
ragmae
xitfun
cti
on2
i
ntmai
n()
{
pri
ntf("\
nNo
wwea
rei
nma
infu
nct
io
n")
;
re
turn0;
}
v
oidfunc
ti
on1
()
{
pri
ntf(
"\
nFunc
ti
on1i
sca
lle
dbe
for
ema
infu
nct
io
nca
ll"
);
}
v
oidfunc
ti
on2()
{
pri
ntf("\
nFun
cti
on2i
scal
le
dju
stb
efo
ree
ndo
f"\
"mai
nfunct
io
n");"
}
97
OUTPUT:
Fu
nct
io
n1i
sca
lle
dbe
for
ema
infu
nct
io
nca
llNo
w
wea
rei
nma
infu
nct
io
n
Fu
nct
io
n2i
sca
lle
dju
stb
efo
ree
ndo
fma
infu
nct
io
n
MOREONPRAGMADI
RECTI
VEI
NC:
S.
no Pr
agmac
omma
nd d
esc
rip
tio
n
#Pr
agmas
tar
tup Thi
sdi
rec
ti
vee
xec
ute
sfu
nct
io
nna
med
1 <
fun
cti
on_n
ame
_1> ―fu
nct
io
n_n
ame
_1‖b
efo
re
Thi
sdi
rec
ti
vee
xec
ute
sfu
nct
io
n
#Pr
agmae
xit n
ame
d―fu
nct
io
n_n
ame
_2‖j
ust
2 <
fun
cti
on_n
ame
_2> b
efo
ret
ermi
nat
io
noft
hep
rogr
am.
I
ffu
nct
io
ndo
esn
‘tr
etu
rnav
alu
e,
t
henwa
rni
ngsa
res
upp
res
sedb
y
3 #p
ragmawa
rn–r
vl t
hisd
ire
cti
vewhi
lec
omp
il
in
g.
I
ffu
nct
io
ndo
esn
‘tu
sep
ass
edfu
nct
io
n
p
ara
met
er,t
henwa
rni
ngsa
re
4 #p
ragmawa
rn–p
ar s
upp
res
sed
I
fan
onr
eac
hab
lec
odei
swr
itt
en
i
nsi
deap
rogr
am,s
uchwa
rni
ngs
5 #p
ragmawa
rn–r
ch a
res
upp
res
sedb
ythi
sdi
rec
ti
ve.
98
POI
NTERS
Po
int
erOv
erv
iew
Co
nsi
dera
bov
eDi
agr
amwhi
chc
lea
rlys
howsp
oin
terc
onc
epti
ncp
rogr
ammi
ng–
ii
sthen
amegi
venfo
rpa
rti
cul
arme
mor
ylo
cat
io
nofo
rdi
nar
yva
ria
ble
.
Le
tusc
ons
ide
rit
‘sCo
rre
spo
ndi
nga
ddr
essb
e65624a
ndt
heVa
lues
tor
edi
nva
ria
ble„
i‟i
s5
The
add
res
soft
hev
ari
abl
e„i
‟i
ss
tor
edi
nan
othe
rin
tege
rva
ria
ble
who
sen
ame
is
„j‟
and
whi
c
hisha
vin
g
c
orr
esp
ond
inga
ddr
ess
65522
t
huswec
ans
ayt
hat–
j=&i
;
i
.e
j=Ad
dre
sso
fi
He
reji
sno
tor
din
aryv
ari
abl
e,I
tiss
pec
ialv
ari
abl
ean
dca
lle
dpo
int
erv
ari
abl
easi
tst
ore
sthe
a
ddr
esso
fthea
not
hero
rdi
nar
yva
ria
ble
.Wec
ans
umma
riz
eitl
ike–
Va
ria
bleNa
me Va
ria
bleVa
lue Va
ria
bleAd
dre
ss
i 5 65524
j 65524 65522
B.CPo
int
erBa
sicEx
amp
le:
#i
ncl
ude
<st
dio
.h>
i
ntmai
n()
{
i
nt*
ptr,i
;
i=1
1;
/*a
ddr
esso
fii
sas
si
gne
dtop
tr*
/
99
p
tr=&i
;
/*sho
wi'
sva
lueus
ingp
trv
ari
abl
e*/p
rin
tf(
"Va
lue
ofi:%d"
,*p
tr)
;
r
etu
rn0;
}
Se
eOutp
utan
dDo
wnl
oad»
Yo
uwi
llge
tva
lueo
fi=1
1i
nthea
bov
epr
ogr
am.
C.Po
int
erDe
cla
rat
io
nTi
ps:
1
.Po
int
eri
sde
cla
redwi
thp
rec
edi
ng*
:
i
nt*
ptr
;//
Her
ept
risI
nte
gerPo
int
erVa
ria
ble
i
ntp
tr;/
/He
rep
tri
sNo
rma
lIn
tege
rVa
ria
ble
2.Whi
te
spa
cewhi
leWr
iti
ngPo
int
er:
p
oin
terv
ari
abl
ena
mea
nda
ste
ris
kca
nco
nta
inwhi
te
spa
ceb
eca
usewhi
te
spa
cei
sign
ore
dby
c
omp
il
er.
i
nt*
ptr
;
i
nt *p
tr;
i
nt* p
tr;
Al
lthea
bov
esy
nta
xar
ele
gala
ndv
ali
d.Wec
ani
nse
rta
nyn
umb
ero
fsp
ace
sorb
lan
ksi
nsi
ded
ecl
ara
tio
n.
Wec
ana
lsos
pli
tthed
ecl
ara
tio
nonmu
lti
pl
eli
nes
.
D.Ke
ypo
int
sfo
rPo
int
er:
Un
li
neo
rdi
nar
yva
ria
ble
spo
int
eri
ssp
eci
alt
ypeo
fva
ria
blewhi
chs
tor
est
hea
ddr
esso
for
din
ary
v
ari
abl
e.
Po
int
erc
ano
nlys
tor
ethewho
leo
rin
tege
rnu
mbe
rbe
cau
sea
ddr
esso
fan
yty
peo
fva
ria
blei
sco
nsi
der
eda
s
i
nte
ger
.
I
tisgo
odt
oin
iti
al
iz
ethep
oin
teri
mme
dia
tel
yaft
erd
ecl
ara
tio
n&
s
ymb
oli
sus
edt
oge
tad
dre
sso
fva
ria
ble
*s
ymb
oli
sus
edt
oge
tva
luefr
omt
hea
ddr
essgi
venb
ypo
int
er.
E.Po
int
erSu
mma
ry:
Po
int
eri
sSp
eci
alVa
ria
bleu
sedt
oRe
fer
enc
ean
dde
-re
fer
enc
eme
mor
y.(
*Wi
llb
eco
ver
edi
n
u
pco
min
gcha
pte
r)
1
00
Whe
nwed
ecl
arei
nte
gerp
oin
tert
henwec
ano
nlys
tor
ead
dre
sso
fin
tege
rva
ria
blei
ntot
hat
p
oin
ter
.
Si
mil
arl
yifwed
ecl
arec
har
act
erp
oin
tert
heno
nlyt
hea
ddr
esso
fcha
rac
terv
ari
abl
eiss
tor
edi
nto
t
hep
oin
terv
ari
abl
e.
Po
int
ers
tor
ingt
hea
ddr
esso
ffo
ll
owi
ngDT Po
int
eri
sca
lle
das
I
nte
ger I
nte
gerPo
int
er
Cha
rac
ter Cha
rac
terPo
int
er
Do
ubl
e Do
ubl
ePo
int
er
Fl
oat Fl
oatPo
int
er
Po
int
eri
sav
ari
abl
ewhi
chs
tor
est
hea
ddr
esso
fan
othe
rva
ria
ble
Si
ncePo
int
eri
sal
soaki
ndo
fva
ria
ble,t
husp
oin
teri
ts
elfwi
llb
est
ore
datd
iffe
ren
tme
mor
y
l
oca
tio
n.
2Ty
peso
fVa
ria
ble
s:
Si
mpl
eVa
ria
blet
hats
tor
esav
alu
esu
cha
sin
tege
r,f
loa
t,c
har
act
er
Co
mpl
exVa
ria
blet
hats
tor
esa
ddr
esso
fsi
mpl
eva
ria
blei
.ep
oin
terv
ari
abl
es
Si
mpl
ePo
int
erEx
amp
le#1:
#i
ncl
ude
<st
dio
.h>
i
ntmai
n(
)
{
i
nta=3;
i
nt*
ptr
;
p
tr=&a;
re
turn
(0)
;
}
Expl
anat
io
nofEx
amp
le:
Po
int Va
ria
ble'
a' Va
ria
ble'
pt
r'
Na
meo
fVa
ria
ble a p
tr
1
01
Po
int Va
ria
ble'
a' Va
ria
ble'
pt
r'
Ty
peo
fVa
luet
hati
tho
lds I
nte
ger Ad
dre
sso
fIn
tege
r'a
'
Va
lueSt
ore
d 3 2001
Ad
dre
sso
fVa
ria
ble 2001(
Ass
ump
tio
n) 4
001(
Ass
ump
tio
n)
Si
mpl
ePo
int
erEx
amp
le#2:
#i
ncl
ude
<st
dio
.h>
i
ntmain(
)
{
i
nta=3;
i
nt*pt
r,*
*pptr
;
pt
r=&a;
pp
tr=&p t
r ;
re
turn
(0);
}
Expl
anat
ionofEx
amp
le
Wi
thr
efe
ren
cet
oab
ovep
rogr
am–
Weha
vefo
ll
owi
nga
sso
cia
tedp
oin
ts–
Po
int Va
ria
ble'
a' Va
ria
ble'
pt
r' Va
ria
ble'
ppt
r'
Na
meo
fVa
ria
ble a p
tr p
ptr
Ty
peo
fVa
luet
hati
tho
lds I
nte
ger Ad
dre
sso
f'a
' Ad
dre
sso
f'p
tr'
Va
lueSt
ore
d 3 2001 4
001
1
02
Po
int Va
ria
ble'
a' Va
ria
ble'
pt
r' Va
ria
ble'
ppt
r'
Ad
dre
sso
fVa
ria
ble 2001 4
001 6001
Po
int
era
ddr
esso
per
ato
rinCPr
ogr
ammi
ng
Po
int
era
ddr
ess
ope
rat
ori
sde
not
edb
y‗&‘
symb
ol
Whe
nweu
sea
mpe
rsa
nds
ymb
ola
sap
ref
ixt
oav
ari
abl
ena
me‗
&‘,i
tgi
vest
hea
ddr
esso
ftha
t
v
ari
abl
e.
l
etst
akea
nex
amp
le–
&n-I
tgi
vesa
nad
dre
sso
nva
ria
blen
Wo
rki
ngo
fad
dre
sso
per
ato
r
#i
ncl
ude
<std
io.
h>
vo
idmai
n()
{
i
ntn=10;
pr
int
f("
\nVal
ueofni
s:%d"
,n)
;
pr
int
f("
\nVal
ueof&ni
s:%u"
,&n)
;
}
Outp
ut:
Va
lueo
fni
s:1
0Va
lue
o
f&ni
s:1
002
Co
nsi
dert
hea
bov
eex
amp
le,whe
reweha
veu
sedt
opr
intt
hea
ddr
esso
fthev
ari
abl
eus
ing
a
mpe
rsa
ndo
per
ato
r.
I
nor
dert
opr
intt
hev
ari
abl
ewes
imp
lyu
sen
ameo
fva
ria
blewhi
let
opr
intt
hea
ddr
esso
fthe
v
ari
abl
eweu
sea
mpe
rsa
nda
lon
gwi
th%u
p
rin
tf(
"\
nVa
lueo
f&ni
s:%u
",&n
);
Un
der
sta
ndi
nga
ddr
esso
per
ato
r
Co
nsi
dert
hefo
ll
owi
ngp
rogr
am–
#i
ncl
ude<
std
io.
h>
i
ntmain
()
{
i
nti=5;
i
nt*p
tr;
1
03
p
tr=&i
;
p
rin
tf(
"\
nAd
dres
sofi :%u",
&i)
;
p
rin
tf(
"\
nVa
lueofpt
ris:
%u"
,pt
r);
re
turn
(0)
;
}
Afte
rdec
lar
ati
onme
mor
yma
pwi
llb
eli
ket
his–
i
nti=5;
i
nt*
ptr
;
a
fte
rAs
si
gni
ngt
hea
ddr
esso
fva
ria
blet
opo
int
er,i
.ea
fte
rthee
xec
uti
ono
fthi
sst
ate
men
t–
p
tr=
&i;
I
nva
li
dUs
eofp
oin
tera
ddr
esso
per
ato
r
Ad
dre
sso
fli
te
ral
s
I
nCp
rogr
ammi
ngu
sin
gad
dre
sso
per
ato
rov
erl
it
era
lwi
llt
hro
wane
rro
r.Wec
ann
otu
sea
ddr
esso
per
ato
r
o
nthel
it
era
ltoge
tthea
ddr
esso
fthel
it
era
l.
&7
5
On
lyv
ari
abl
esha
vea
nad
dre
ssa
sso
cia
tedwi
tht
hem,c
ons
tan
ten
tit
ydo
esn
otha
ve
c
orr
esp
ond
inga
ddr
ess
.Si
mil
arl
ywec
ann
otu
sea
ddr
esso
per
ato
rov
erc
har
act
erl
it
era
l–
&(
'
a')
Cha
rac
ter‗
a‘i
sli
te
ral
,sowec
ann
otu
sea
ddr
esso
per
ato
r.
Ad
dre
sso
fex
pre
ssi
ons
1
04
(
a+b
)wi
lle
val
uat
ead
dit
io
nofv
alu
esp
res
enti
nva
ria
ble
san
dou
tpu
tof(
a+b
)i
sno
thi
ngb
ut
Li
te
ral
,sowec
ann
otu
seAd
dre
sso
per
ato
r
&(
a+b
)
Me
mor
yOr
gan
iza
tio
nfo
rPo
int
erVa
ria
ble
:
Whe
nweu
sev
ari
abl
einp
rogr
amt
henCo
mpi
le
rke
epss
omeme
mor
yfo
rtha
tva
ria
bled
epe
ndi
ngo
n
t
hed
atat
ype
Thea
ddr
essgi
vent
othev
ari
abl
eisUn
iqu
ewi
tht
hatv
ari
abl
ena
me
Whe
nPr
ogr
ame
xec
uti
ons
tar
tst
hev
ari
abl
ena
mei
sau
toma
tic
all
ytr
ans
lat
edi
ntot
he
c
orr
esp
ond
inga
ddr
ess
.
Ex
pla
nat
io
n:
Po
int
erVa
ria
ble
isn
othi
ngb
utame
mor
yad
dre
sswhi
chho
ldsa
not
hera
ddr
ess.
I
nthe
abo
vep
rogr
am―i
‖i
sna
megi
ven
for
memo
ryl
oca
tio
nfo
rhu
man
und
ers
tan
din
g,b
ut
c
omp
il
eri
sun
abl
eto
rec
ogn
ize
―i‖
.Co
mpi
le
rkn
ows
onl
yad
dre
ss.
I
nthen
extc
hap
terwewi
llb
ele
arn
ing,Me
mor
yre
qui
reme
ntfo
rst
ori
ngp
oin
terv
ari
abl
e.
Sy
nta
xfo
rPo
int
erDe
cla
rat
io
ninC:
d
ata
_ty
pe*
<po
int
er_n
ame
>;
Ex
pla
nat
io
n:
d
ata
_ty
pe
Ty
peo
fva
ria
blet
hatt
hep
oin
terp
oin
tst
o
ORd
atat
ypewho
sea
ddr
essi
sst
ore
dinp
oin
ter
_na
me
As
ter
isk(
*)
As
ter
iski
sca
lle
dasI
ndi
rec
tio
nOp
era
tor
I
tisa
lsoc
all
eda
sVa
luea
tad
dre
ssOp
era
tor
I
tIn
dic
ate
sVa
ria
bled
ecl
are
diso
fPo
int
ert
ype
1
05
p
oin
ter
_na
me
Mu
stb
ean
yVa
li
dCi
den
tifi
er
Mu
stfo
ll
owa
llRu
leso
fVa
ria
blen
amed
ecl
ara
tio
n
Wa
yso
fDe
cla
rin
gPo
int
erVa
ria
ble
:
[
box
]*c
ana
ppe
arsa
nywhe
reb
etwe
enPo
int
er_n
amea
ndDa
taTy
pe
i
nt*
p;
i
nt* p;
i
nt *p;
Ex
amp
leo
fDe
cla
rin
gIn
tege
rPo
int
er:
i
ntn=20;
i
nt*
ptr
;
Ex
amp
leo
fDe
cla
rin
gCha
rac
terPo
int
er:
c
harc
h='
A'
;
c
har*
cpt
r;
Ex
amp
leo
fDe
cla
rin
gFl
oatPo
int
er:
fl
oatfv
ar=3.
14;
fl
oat*
fpt
r;
Ho
wtoI
ni
ti
al
iz
ePo
int
eri
nCPr
ogr
ammi
ng?p
oin
ter
=&v
ari
abl
e;
Ab
ovei
sthes
ynt
axfo
rin
iti
al
iz
ingp
oin
terv
ari
abl
einC.
I
ni
ti
al
iz
ati
ono
fPo
int
erc
anb
edo
neu
sin
gfo
ll
owi
ng4St
eps:
De
cla
reaPo
int
erVa
ria
blea
ndNo
ted
ownt
heDa
taTy
pe.
De
cla
rea
not
herVa
ria
blewi
thSa
meDa
taTy
pea
stha
tofPo
int
erVa
ria
ble
.
I
ni
ti
al
iz
eOr
din
aryVa
ria
blea
nda
ssi
gns
omev
alu
etoi
t.
No
wIn
iti
al
iz
epo
int
erb
yas
si
gni
ngt
hea
ddr
esso
for
din
aryv
ari
abl
etop
oin
terv
ari
abl
e.
b
elo
wexamp
lewi
llc
lea
rlye
xpl
ai
nthei
ni
ti
al
iz
ati
ono
fPo
int
erVa
ria
ble
.#i
ncl
ude
<st
dio
.h>
i
ntmai
n(
)
{
i
nta
; //St e
p1
i
nt*pt
r; //
St
ep2
1
06
a=
10; //St
ep
3ptr=&a
;//
St
ep4
re
turn
(0)
;
}
Expl
anat
io
nofAb
ovePr
ogr
am:
Po
int
ers
hou
ldn
otb
eus
edb
efo
rei
ni
ti
al
iz
ati
on.
―p
tr‖
is
poi
nte
rva
ria
ble
use
dto
sto
ret
hea
ddr
ess
oft
hev
ari
abl
e.St
ore
s
a
ddr
esso
fthev
ari
abl
e„a
‟.
No
w―pt
r‖wi
llc
ont
aint
hea
ddr
esso
fthev
ari
abl
e―a
‖.
No
te:
[
box
]Po
int
ersa
rea
lwa
ysi
ni
ti
al
iz
edb
efo
reu
sin
giti
nthep
rogr
am[
/bo
x]
Ex
amp
le:I
ni
ti
al
iz
ingI
nte
gerPo
int
er
#i
ncl
ude<
std
io.
h>
i
ntmain
()
{
i
nta=10;
i
nt*p
tr;
p
tr=&a;
p
rin
tf(
"\
nVa
lueo
fpt
r:%u
",p
tr)
;
re
tur
n(0)
;
}
Out
put:
Va
lueo
fpt
r:4
001
Po
int
era
rit
hema
tic
I
ncr
eme
nti
ngPo
int
er:
I
ncr
eme
nti
ngPo
int
eri
sge
ner
all
yus
edi
nar
rayb
eca
useweha
vec
ont
igu
ousme
mor
yina
rra
yan
dwe
kn
owt
hec
ont
ent
sofn
extme
mor
ylo
cat
io
n.
I
ncr
eme
nti
ngPo
int
erVa
ria
bleDe
pen
dsUp
ond
atat
ypeo
fthePo
int
erv
ari
abl
e
Fo
rmu
la:(Aft
eri
ncr
eme
nti
ng)
n
ewv
alu
e=c
urr
enta
ddr
ess+i
*si
ze_o
f(d
atat
ype
)Thr
ee
Ru
less
hou
ldb
eus
edt
oin
cre
men
tpo
int
er–
1
07
Ad
dre
ss+1=Ad
dre
ss
Ad
dre
ss++ =
Add
res
s
++Ad
dre
ss=
Add
res
s
Pi
cto
ria
lRe
pre
sen
tat
ion:
Da
taTy
pe Ol
derAd
dre
sss
tor
edi
n Ne
xtAd
dre
sss
tor
edi
npo
int
era
fte
r
p
oin
ter i
ncr
eme
nti
ng(
ptr
++)
i
nt 1
000 1
002
fl
oat 1
000 1
004
c
har 1
000 1
001
Ex
pla
nat
io
n:I
ncr
eme
ti
ngPo
int
er
I
ncr
eme
nti
ngap
oin
tert
oani
nte
gerd
atawi
llc
aus
eit
sva
luet
obei
ncr
eme
nte
dby2.
Thi
sdi
ffe
rsfr
omc
omp
il
ert
oco
mpi
le
rasme
mor
yre
qui
redt
ost
orei
nte
gerv
aryc
omp
ile
rto
c
omp
ile
r
[
box
]No
tet
oRe
memb
er:I
ncr
eme
nta
ndDe
cre
men
tOp
era
tio
nso
npo
int
ers
hou
ldb
eus
edwhe
n
weha
veCo
nti
nue
sme
mor
y(i
nAr
ray
).[
/bo
x]
Li
veEx
amp
le1:I
ncr
eme
ntI
nte
gerPo
int
er
#i
ncl
ude
<st
dio
.h>
i
ntma
in(
){
i
nt*
ptr
=(i
nt*
)1
000;
p
tr=pt
r+1;
p
rin
tf("
NewVa
lueo
fpt
r:%u
",p
tr)
;
1
08
r
etu
rn0;
}
Ou
tpu
t:
Ne
wVa
lueo
fpt
r:1
002
Li
veEx
amp
le2:I
ncr
eme
ntDo
ubl
ePo
int
er
#i
ncl
ude
<st
dio
.h>
i
ntma
in(
){
d
oub
le*
ptr
=(d
oub
le*
)1
000;
p
tr=pt
r+1;
p
rin
tf("
NewVa
lueo
fpt
r:%u
",p
tr)
;
re
tur
n0;
}
Out
put:
Ne
wVa
lueo
fpt
r:1
004
Li
veEx
amp
le3:Ar
rayo
fPo
int
er
#i
ncl
ude
<st
dio
.h>
i
ntma
in(
){
fl
oat
va
r[5]={
1.1
f,2.
2f,
3.3f}
;
fl
oat(
*pt
r)[
5];
p
tr=&v
ar;
p
rin
tf(
"Val
uei
nsi
dep
tr:%u
",p
tr)
;
p
tr=pt
r+1;
p
rin
tf("
Valuei
nsi
dep
tr:%u
",p
tr)
;
re
tur
n0;
}
Out
put:
Va
luei
nsi
dep
tr:1
000
Va
luei
nsi
dep
tr:1
020
1
09
Ex
pla
nat
io
n:
Ad
dre
sso
fpt
r[0]=1
000
Wea
res
tor
ingAd
dre
sso
ffl
oata
rra
ytop
tr[
0].
–Ad
dre
sso
fpt
r[1
]
=Ad
dre
sso
fpt
r[0]+(
Siz
eofDa
taTy
pe)
*(
Siz
eofAr
ray
)
=1
000+(
4by
tes
)*(
5)
=1
020
Ad
dre
sso
fVa
r[0]
…Va
r[4]:
Ad
dre
sso
fva
r[0]=1
000Ad
dre
ss
o
fva
r[1
]=1
004Ad
dre
sso
fva
r[2]
=1
008Ad
dre
sso
fva
r[3]=1
012
Ad
dre
sso
fva
r[4
]=1
016Fo
rmu
la:
(Aft
erd
ecr
eme
nti
ng)
n
ew_a
ddr
ess=(
cur
ren
tad
dre
ss)-i
*si
ze_o
f(d
atat
ype
)
[
box
]De
cre
men
tat
io
nofPo
int
erVa
ria
bleDe
pen
dsUp
on:d
atat
ypeo
fthePo
int
erv
ari
abl
e[/b
ox]Ex
amp
le:
1
10
Da
taTy
pe Ol
derAd
dre
sss
tor
edi
n Ne
xtAd
dre
sss
tor
edi
npo
int
era
fte
r
p
oin
ter i
ncr
eme
nti
ng(
ptr
–)
i
nt 1
000 0998
fl
oat 1
000 0996
c
har 1
000 0999
Ex
pla
nat
io
n:
De
cre
men
tin
gap
oin
tert
oani
nte
gerd
atawi
llc
aus
eit
sva
luet
obed
ecr
eme
nte
dby2
Thi
sdi
ffe
rsfr
omc
omp
il
ert
oco
mpi
le
rasme
mor
yre
qui
redt
ost
orei
nte
gerv
aryc
omp
ile
rto
c
omp
ile
r
Po
int
erPr
ogr
am:Di
ffe
ren
ceb
etwe
ent
woi
nte
gerPo
int
ers
#i
ncl
ude
<st
dio
.h>
i
ntma
in(
){
fl
oat*
ptr
1=(
flo
at*)
1000;
fl
oat*
ptr
2=(fl
oat*
)2000;
p
rin
tf(
"\
nDi
ffe
ren
ce:%d
",p
tr2-
ptr
1)
;
re
tur
n0;
}
Out
put:
Di
ffe
ren
ce:250
Ex
pla
nat
io
n:
Pt
r1a
ndPt
r2a
ret
wop
oin
ter
swhi
chho
ldsme
mor
yad
dre
sso
fFl
oatVa
ria
ble
.
Pt
r2-
Ptr
1wi
llgi
vesu
snu
mbe
roffl
oat
ingp
oin
tnu
mbe
rst
hatc
anb
est
ore
d.
p
tr2-p
tr1=(
2000-1
000)/s
ize
of(
flo
at)
=1
000/4
=250
Li
veEx
amp
le2:
#i
ncl
ude
<st
dio
.h>
s
tru
ctv
ar{
1
11
charcv
ar;
i
n ti
var
;
floa
tfvar
;
}
;
i
ntma
in(
){
s
tru
ctv
ar*
ptr
1,*
ptr
2;
p
tr1=(
str
uctva
r*)
1000;
p
tr2=(s
truc
tvar*
)2000;
p
rin
tf(
"Di
ffe
ren
ce=
%d"
,pt
r2-
ptr
1)
;
re
tur
n0;
}
Out
put:
Di
ffe
ren
ce=1
42
Ex
pla
nat
io
n:
p
tr2-
ptr
1=(
2000-1
000)
/Si
zeo
f(s
tru
ctv
ar)
=1
000/(
1+2+4
)
=1
000/7
=1
42
Ad
din
gin
tege
rva
luewi
thPo
int
er
I
nCPr
ogr
ammi
ngwec
ana
dda
nyi
nte
gern
umb
ert
oPo
int
erv
ari
abl
e.I
tisp
erfe
ctl
yle
gali
ncp
rogr
ammi
ng
t
oad
din
tege
rtop
oin
terv
ari
abl
e.
I
nor
dert
oco
mpu
tet
hefi
nalv
alu
ewen
eedt
ous
efo
ll
owi
ngfo
rmu
lae:fi
nal
v
alu
e=(
add
res
s)+(
numb
er*s
izeo
fda
tat
ype
)
Co
nsi
dert
hefo
ll
owi
nge
xamp
le–
i
nt*
ptr,n
;
p
tr=&n;
p
tr=p
tr+3
;
Li
veEx
amp
le1:I
ncr
eme
ntI
nte
gerPo
int
er
#i
ncl
ude
<st
dio
.h>
i
ntma
in(
){
i
nt*
ptr
=(i
nt*
)1
000;
1
12
p
tr=pt
r+3;
p
rin
tf("
NewVa
lueo
fpt
r:%u
",p
tr)
;
re
tur
n0;
}
Out
put:
Ne
wVa
lueo
fpt
r:1
006
Ex
pla
nat
io
nofPr
ogr
am:
I
nthea
bov
epr
ogr
am–
i
nt*
ptr
=(i
nt*
)1
000;
t
hisl
in
ewi
lls
tor
e1000i
nthep
oin
terv
ari
abl
eco
nsi
der
ing1
000i
sme
mor
ylo
cat
io
nfo
ran
yoft
he
i
nte
gerv
ari
abl
e.
Fo
rmu
la:
p
tr=p
tr+3*(
si
zeo
f(i
nte
ger
))
=1
000+3*(
2)
=1
000+6
=1
006
Si
mil
arl
yifweha
vewr
itt
ena
bov
est
ate
men
tli
ket
his–
fl
oat*
ptr
=(fl
oat*
)1
000;
t
henr
esu
ltma
ybe
p
tr=p
tr+3*(
si
zeo
f(fl
oat
))
=1
000+3*(
4)
=1
000+1
2
=1
012
Su
ppo
seweha
ves
ubt
rac
ted―n
‖fr
omp
oin
tero
fan
yda
tat
ypeha
vin
gin
iti
ala
dde
ssa
s
―i
ni
t_a
ddr
ess‖t
hena
fte
rsu
btr
act
io
nwec
anwr
ite–p
tr
=i
ni
ti
al
_ad
dre
ss-n*(
si
zeo
f(d
ata
_ty
pe)
)
Su
btr
act
ingi
nte
gerv
alu
ewi
thPo
int
er
i
nt*
ptr,n
;
p
tr=&n;
p
tr=p
tr-
3;
1
13
Li
veEx
amp
le1:De
cre
men
tIn
tege
rPo
int
er
#i
ncl
ude
<st
dio
.h>
i
ntma
in(
){
i
nt*
ptr
=(i
nt*
)1
000;
p
tr=
ptr
-3;
p
rin
tf(
"Ne
wVa
lueo
fpt
r:%u
",p
tr)
;
r
etu
rn0;
}
Ou
tpu
t:
Ne
wVa
lueo
fpt
r:994
Fo
rmu
la:
p
tr=p
tr-3*(
si
zeo
f(i
nte
ger
))
=1
000-3*(
2)
=1
000-6
=994
Su
mma
ry:
Po
int
er-Po
int
er=I
nte
ger
Po
int
er-I
nte
ger=Po
int
er
Di
ffe
ren
cin
gPo
int
eri
nCPr
ogr
ammi
ngLa
ngu
age:
Di
ffe
ren
cin
gMe
ansSu
btr
act
ingt
woPo
int
ers
.
Su
btr
act
io
ngi
vest
heTo
taln
umb
ero
fob
jec
tsb
etwe
ent
hem.
Su
btr
act
io
nin
dic
ate
s―Ho
wap
artt
het
woPo
int
ersa
re?‖
CPr
ogr
amt
oCo
mpu
teDi
ffe
ren
ceBe
twe
enPo
int
ers:
#i
ncl
ude
<st
dio
.h>
i
ntma
in(
)
{
1
14
i
ntn
um,*
ptr
1,*
ptr
2;
p
tr1=&n
um;
p
tr2=pt
r1+2;
p
rin
tf(
"%d
",p
tr2-p
tr1
);
re
tur
n(0)
;
}
Out
put:
2
pt
r1st
ore
sthea
ddr
esso
fVa
ria
blen
um
Va
lueo
fpt
r2i
sin
cre
men
tedb
y4b
yte
s
Di
ffe
ren
cin
gtwoPo
int
ers
I
mpo
rta
ntOb
ser
vat
io
ns:
Su
ppo
set
heAd
dre
sso
fVa
ria
blen
um=1
000.
St
ate
men
t Va
lueo
fPt
r1 Va
lueo
fPt
r2
i
ntn
um,*
ptr
1,*
ptr
2; Ga
rba
ge Ga
rba
ge
p
tr1=&n
um; 1
000 Ga
rba
ge
p
tr2=p
tr1+2; 1
000 1
004
p
tr2-p
tr1 1
000 1
004
Co
mpu
tat
io
nofPt
r2–Pt
r1:
Re
memb
ert
hefo
ll
owi
ngfo
rmu
lawhi
lec
omp
uti
ngt
hed
iffe
ren
ceb
etwe
ent
wop
oin
ter
s–
Fi
nalRe
sul
t=(
ptr
2-p
tr1
)/Si
zeo
fDa
taTy
pe
St
ep1:Co
mpu
teMa
the
mat
ic
alDi
ffe
ren
ce(
Nume
ric
alDi
ffe
ren
ce)p
tr2
-p
tr1=Va
lueo
fPt
r2-Va
lueo
fPt
r1
=1
004-1
000
=4
St
ep2:Fi
ndi
ngAc
tua
lDi
ffe
ren
ce(
Tec
hni
calDi
ffe
ren
ce)
Fi
nalRe
sul
t=4/Si
zeo
fIn
tege
r
=4/2
=2
1
15
Nu
mer
ica
llySu
btr
act
io
n(p
tr2-
ptr
1)d
iffe
rsb
y4
Asb
otha
reI
nte
ger
sthe
yar
enu
mer
ica
llyDi
ffe
redb
y4a
ndTe
chn
ica
llyb
y2o
bje
cts
Su
ppo
seBo
thp
oin
ter
soffl
oatt
het
heywi
llb
edi
ffe
redn
ume
ric
all
yby8a
ndTe
chn
ica
llyb
y2
o
bje
cts
Co
nsi
dert
heb
elo
wst
ate
men
tan
dre
fert
hefo
ll
owi
ngt
abl
e–
i
ntn
um=p
tr2-p
tr1
;
a
nd
I
fTwoPo
int
ersa
reo
fFo
ll
owi
ngDa
ta Nu
mer
ica
l Te
chn
ica
l
Ty
pe Di
ffe
ren
ce Di
ffe
ren
ce
I
nte
ger 2 1
Fl
oat 4 1
Cha
rac
ter 1 1
Co
mpa
ris
onb
etwe
ent
woPo
int
ers:
Po
int
erc
omp
ari
soni
sVa
li
don
lyi
fthet
wop
oin
ter
sar
ePo
int
ingt
osa
mea
rra
y
Al
lRe
lat
io
nalOp
era
tor
sca
nbeu
sedfo
rco
mpa
rin
gpo
int
erso
fsa
met
ypeAl
l
Eq
ual
it
yan
dIn
equ
ali
tyOp
era
tor
sca
nbeu
sedwi
tha
llPo
int
ert
ype
sPo
int
ers
c
ann
otb
eDi
vi
dedo
rMu
lti
pli
ed
Po
int1:Po
int
erCo
mpa
ris
on
#i
ncl
ude
<st
dio
.h>
i
ntmai
n(
)
{
i
nt*
ptr
1,*
ptr
2;
p
tr1=(
in
t*)
1000;
p
tr2=(i
nt*
)2000;
i
f(p
tr2>p t
r1)
pri
ntf(
"Ptr
2isfa
rfr
omp
tr1
")
;
r
etu
rn(
0);
}
1
16
Po
int
erCo
mpa
ris
ono
fDi
ffe
ren
tDa
taTy
pes:
#i
ncl
ude
<st
dio
.h>
i
ntmain
()
{
i
nt*pt
r1;
fl
oat*
ptr2;
p
tr1=(
int*
)1000;
p
tr2=(flo
at*)2000;
i
f(p
tr2>p t
r1)
pri
ntf(
"Ptr
2isfa
rfr
omp
tr1
")
;
re
turn
(0)
;
}
Expl
anat
io
n:
TwoPo
int
erso
fdi
ffe
ren
tda
tat
ype
sca
nbec
omp
are
d.
I
nthea
bov
epr
ogr
amweha
vec
omp
are
dtwop
oin
ter
sofd
iffe
ren
tda
tat
ype
s.I
t
i
spe
rfe
ctl
yle
gali
nCPr
ogr
ammi
ng.
[
box
]Aswekn
owPo
int
ersc
ans
tor
eAd
dre
sso
fan
yda
tat
ype
,ad
dre
sso
fthed
atat
ypei
s
―I
nte
ger‖s
owec
anc
omp
area
ddr
esso
fan
ytwop
oin
ter
sal
tho
ught
heya
reo
fdi
ffe
ren
tda
tat
ype
s.[
/bo
x]
Fo
ll
owi
ngo
per
ati
onso
npo
int
ers:
> Gr
eat
erTha
n
< Le
ssTha
n
>
= Gr
eat
erTha
nAn
dEq
ualTo
<
= Le
ssTha
nAn
dEq
ualTo
=
= Eq
ual
s
!
= No
tEq
ual
Di
vi
dea
ndMu
lti
pl
yOp
era
tio
ns:
#i
ncl
ude
<st
dio
.h>
1
17
i
ntmai
n(
)
{
i
nt*
ptr
1,*
ptr
2;
p
tr1=(
in
t*)1
000;
p
tr2=ptr
1/4;
re
tur
n(0)
;
}
Out
put:
Po
int
ert
opo
int
er
Po
int
ert
oPo
int
eri
nCPr
ogr
ammi
ng
De
cla
rat
ion:Do
ubl
ePo
int
er
i
nt*
*pt
r2p
tr;
Co
nsi
dert
heFo
llo
win
gEx
amp
le:
i
ntn
um=4
5,*
ptr,*
*pt
r2p
tr;
p
tr=&n
um;
p
tr2p
tr=&p
tr;
Wha
tisPo
int
ert
oPo
int
er?
1
18
Do
ubl
e(*
*)i
sus
edt
ode
not
ethed
oub
lePo
int
er
Po
int
erSt
ore
sthea
ddr
esso
ftheVa
ria
ble
Do
ubl
ePo
int
erSt
ore
sthea
ddr
esso
fthePo
int
erVa
ria
ble
St
ate
men
t Wha
twi
llb
etheOu
tpu
t?
*
ptr 4
5
*
*pt
r2p
tr 4
5
p
tr &n
p
tr2p
tr &p
tr
No
tes:
Co
nce
ptu
all
ywec
anha
veTr
ipl
e….
.np
oin
ter
s
Ex
amp
le:*
**
**
n,*
**
*bc
anb
ean
othe
rex
amp
leLi
ve
Ex
amp
le:
#i
ncl
ude
<st
dio
.h>
i
ntmai
n()
{
i
ntnu
m=4 5,* p
tr,*
*pt
r2p
tr;
p
tr = #
p
tr2p
tr=&p t
r;
p
rin
tf(
"%d
",*
*pt
r2p
tr)
;
1
19
re
tur
n(0)
;
}
Out
put:
4
5
1
20
UNI
T-I
V
STRUCTURESANDUNI
ONS
I
NTRODUCTI
ONTOSTRUCTURE
AsweknowthatArr
ayisco
lle
cti
ono
fthee
leme
ntso
fsa
met
ype,b
utma
nyt
imeweha
vet
ost
ore
thee
leme
ntsofthed
iffe
rentda
taty
pes
.
Sup
poseStu
den
trec
ordi
stobest
ore
d,the
nfors
tor
ingtherec
ordwehav
etogr
oupt
oge
the
ral
lthe
i
nformat
io
nsucha
sRoll
,name,Per
cen
twhic
hmaybeofdiffe
rentd
atat
ype
s.
I
dea
llySt
ruc
tur
eisc
oll
ect
io
nofd
iffe
ren
tva
ria
ble
sun
ders
ingl
ena
me.
Ba
sic
all
ySt
ruc
tur
eisfo
rst
ori
ngt
hec
omp
li
cat
edd
ata
.
As
tru
ctu
rei
sac
onv
eni
entwa
yofgr
oup
ings
eve
ralp
iec
eso
fre
lat
edi
nfo
rma
tio
nto
get
her
.
De
fin
iti
ono
fSt
ruc
tur
einC
St
ruc
tur
eisc
omp
osi
ti
ono
fthed
iffe
ren
tva
ria
ble
sofd
iffe
ren
tda
tat
ype
s,gr
oup
edu
nde
rsa
me
na
me.
t
ype
defs
tru
ct{
c
harn
ame
[64
];
c
harc
our
se[
128]
;
i
nta
ge;
i
nty
ear
;
}s
tud
ent
;
So
meI
mpo
rta
ntDe
fin
iti
onso
fSt
ruc
tur
es
Ea
chme
mbe
rde
cla
redi
nSt
ruc
tur
eisc
all
edme
mbe
r.
c
harn
ame
[64
];
c
harc
our
se[
128]
;
i
nta
ge;
i
nty
ear
;
1
21
a
res
omee
xamp
leso
fme
mbe
rs.
Na
megi
vent
ost
ruc
tur
eisc
all
eda
sta
g
St
ruc
tur
eme
mbe
rma
ybeo
fdi
ffe
ren
tda
tat
ypei
ncl
udi
ngu
serd
efi
nedd
ata
-ty
pea
lso
t
ype
defs
tru
ct{
c
harn
ame
[64
];
c
harc
our
se[
128
];
b
ookb
1;
i
nty
ear
;
}s
tud
ent
;
He
reb
ooki
sus
erd
efi
nedd
ata
typ
e.
De
cla
rin
gSt
ruc
tur
eVa
ria
blei
nC
I
nCwecangroupso
meo ftheu
serd
efi
nedorpri
mit
ived
atatyp
est
oge
theran
dformano
therco
mpact
wayo
fsto
rin
gc omp
lic
atedi
nfo
rmat
io
nisca
lle
dasStruc
ture
.Letuss
eehowtod
ecl
arest
ruct
urei
nc
pr
ogr
ammin
gl a
nguage–
Sy
nta
xofSt
ruc
tur
einCPr
ogr
ammi
ng
s
tru
ctt
ag
d
ata
_ty
pe1 me
mbe
r1;
d
ata
_ty
pe2me
mbe
r2;
d
ata
_ty
pe3me
mbe
r3;
}
;
St
ruc
tur
eAl
ter
nat
eSy
nta
x
s
tru
ct<
str
uct
ure
_na
me>
s
tru
ctu
re_El
eme
nt1
;
s
tru
ctu
re_El
eme
nt2;
1
22
s
tru
ctu
re_El
eme
nt3;
.
..
.
..
}
;
So
meI
mpo
rta
ntPo
int
sRe
gar
din
gSt
ruc
tur
einCPr
ogr
ammi
ng:
St
ruc
tke
ywo
rdi
sus
edt
ode
cla
res
tru
ctu
re.
Me
mbe
rso
fst
ruc
tur
ear
een
clo
sedwi
thi
nop
eni
nga
ndc
los
ingb
rac
es.
De
cla
rat
iono
fSt
ruc
tur
ere
ser
vesn
osp
ace
.
I
tisn
othi
ngb
utt
he―Te
mpl
ate/Ma
p/Sha
pe‖o
fthes
tru
ctu
re.
Me
mor
yisc
rea
ted
,ve
ryfi
rstt
imewhe
nthev
ari
abl
eisc
rea
ted/I
nst
anc
eisc
rea
ted
.
Di
ffe
ren
tWa
yso
fDe
cla
rin
gSt
ruc
tur
eVa
ria
ble
:
Wa
y1:I
mme
dia
tel
yaft
erSt
ruc
tur
eTe
mpl
ate
s
tru
ctd
ate
i
ntd
ate
;
c
harmo
nth[
20]
;
i
nty
ear
;
}
tod
ay;
//'
to
day
'isn
ameo
fSt
ruc
tur
eva
ria
ble
Wa
y2:De
cla
reVa
ria
ble
sus
ings
tru
ctKe
ywo
rd
s
tru
ctd
ate
i
ntd
ate
;
c
harmo
nth[
20]
;
1
23
i
nty
ear
;
}
;
s
tru
ctd
atet
oda
y;
whe
re―d
ate
‖i
sna
meo
fst
ruc
tur
ean
d―t
oda
y‖i
sna
meo
fva
ria
ble
.
Wa
y3:De
cla
rin
gMu
lti
pl
eSt
ruc
tur
eVa
ria
ble
s
s
tru
ctBo
ok
i
ntp
age
s;
c
harn
ame
[20]
;
i
nty
ear
;
}
boo
k1,
boo
k2,
boo
k3;
CSt
ruc
tur
eIn
iti
al
iza
tio
n
Whe
nwed
ecl
areas
tru
ctu
re,me
mor
yisn
ota
llo
cat
edfo
run
-in
iti
al
iz
edv
ari
abl
e.
Le
tusd
isc
ussv
eryfa
mil
ia
rex
amp
leo
fst
ruc
tur
est
ude
nt,wec
ani
ni
ti
al
iz
est
ruc
tur
eva
ria
blei
ndi
ffe
ren
t
wa
ys–
Wa
y1:De
cla
rea
ndI
ni
ti
al
iz
e
s
tru
cts
tud
ent
c
harn
ame
[20]
;
i
ntr
oll
;
fl
oatma
rks
;
}
std
1={"
Pri
te
sh"
,67
,78.
3};
I
ntheabo
vecod
esni
ppe
t,weha
vesee
ntha
tst
ruc
tur
eisd
ecl
are
dan
dass
oona
saft
erd
ecl
ara
tio
nwe
ha
vein
iti
al
iz
edthes
tru
ctu
reva
ria
ble
.
1
24
s
td1={"
Pri
te
sh"
,67
,78.
3}
Thi
sist
hec
odefo
rin
iti
al
iz
ings
tru
ctu
rev
ari
abl
einCp
rogr
ammi
ng
Wa
y2:De
cla
rin
gan
dIn
iti
al
iz
ingMu
lti
pl
eVa
ria
ble
s
s
tru
cts
tud
ent
c
harn
ame
[20]
;
i
ntr
oll
;
fl
oatma
rks
;
s
td1={
"Pr
ite
sh"
,67
,78.
3};
s
td2={
"Do
n",
62,
71.
3};
I
nthi
sex
ample,wehav
edecl
are
dtwos
tru
ctu
rev
ari
abl
esi
nab
ovec
ode
.Aft
erd
ecl
ara
tio
nofv
ari
abl
e
weha
vei
nit
ial
ize
dtwovar
iab
le.
s
td1={
"Pr
ite
sh"
,67
,78.
3};
s
td2={
"Do
n",
62,
71.
3};
Wa
y3:I
ni
ti
al
iz
ingSi
ngl
eme
mbe
r
s
tru
cts
tud
ent
i
ntma
rk1
;
i
ntma
rk2;
i
ntma
rk3
;
}
sub
1={
67}
;
Thoughthe
rearethr
eeme
mbe
rsofst
ruc
tur
e,o
nlyonei
sini
ti
ali
zed,Thenr
emain
ingtwo
membersar
ein
iti
al
ize
dwit
hZer
o.Ift
herea
revari
abl
esofothe
rd a
taty
pethe
ntheiri
ni
ti
al
val
ueswil
lbe–
1
25
Da
taTy
pe De
fau
ltv
alu
eifn
oti
ni
ti
al
ize
d
i
nte
ger 0
fl
oat 0.
00
c
har NULL
Wa
y4:I
ni
ti
al
iz
ingi
nsi
dema
in
s
tru
cts
tud
ent
i
ntma
rk1
;
i
ntma
rk2;
i
ntma
rk3;
}
;
v
oidma
in(
)
s
tru
cts
tud
ents
1={
89,
54,
65}
;
----
--
----
--
----
--
}
;
Whenwedec
lar
east
ruct
uret
henmemor
ywon‘tb
eall
oca
tedfo
rthes
tru
ctu
re.i
.eo
nlywr
iti
ng
b
elo
wdecl
arat
io
nst
ate
mentwi
llne
vera
llo
cat
ememor
y
s
tru
cts
tud
ent
1
26
i
ntma
rk1
;
i
ntma
rk2;
i
ntma
rk3;
}
;
Wen
eedt
oin
iti
al
iz
est
ruc
tur
eva
ria
blet
oal
lo
cat
eso
meme
mor
ytot
hes
tru
ctu
re.
s
tru
cts
tud
ents
1={
89,
54,
65}
;
So
meSt
ruc
tur
eDe
cla
rat
io
nsa
ndI
t‘
sMe
ani
ng:
s
tru
ct
i
ntl
engt
h;
c
har*
name
;
}
*pt
r;
Su
ppo
sewei
ni
ti
al
iz
ethe
set
wos
tru
ctu
reme
mbe
rswi
thfo
ll
owi
ngv
alu
es–
l
engt
h=30;
*
name="
pro
gra
mmi
ng"
;
No
wCo
nsi
derFo
ll
owi
ngDe
cla
rat
io
nso
neb
yOn
e–
Ex
amp
le1:I
ncr
eme
nti
ngMe
mbe
r
++p
tr-
>le
ngt
h
―++‖Op
era
tori
spr
e-i
ncr
eme
nto
per
ato
r.
1
27
Ab
oveSt
ate
men
twi
lli
ncr
eas
ethev
alu
eof―l
engt
h―
Ex
amp
le2:I
ncr
eme
nti
ngMe
mbe
r
(
++p
tr)
->l
engt
h
Co
nte
nto
fthel
engt
hisfe
tche
dan
dthe
npt
risi
ncr
eme
nte
d.
Co
nsi
dera
bov
eSt
ruc
tur
ean
dLo
oka
ttheFo
llo
win
gTa
ble
:-
Ex
pre
ssi
on Me
ani
ng
++p
tr-
>le
ngt
h I
ncr
eme
ntt
hev
alu
eofl
engt
h
(
++p
tr)
->l
engt
h I
ncr
eme
ntp
trb
efo
rea
cce
ssi
ngl
engt
h
(
ptr
++)
->l
engt
h I
ncr
eme
ntp
tra
fte
rac
ces
si
ngl
engt
h
*
ptr
->n
ame Fe
tchCo
nte
nto
fna
me
*
ptr
->n
ame
++ I
ncr
eme
nti
ngp
tra
fte
rFe
tchi
ngt
hev
alu
e
(
*pt
r->
name
)++ I
ncr
eme
ntswha
tev
ers
trp
oin
tst
o
*
ptr
++-
>na
me I
ncr
eme
nti
ngp
tra
fte
rac
ces
si
ngwha
tev
ers
trp
oin
tst
o
Ac
ces
sin
gSt
ruc
tur
eMe
mbe
rs
Arra
yele
mentsa
rea
cce
sse
dusin
gtheSu
bsc
rip
tva
ria
ble
,Si
mil
arl
ySt
ruc
tur
eme
mbe
rsa
re
ac
cess
edus
ingdo
t[.
]oper
ato
r.
(
.)
isc
all
eda
s―St
ruc
tur
eme
mbe
rOp
era
tor‖
.
Us
ethi
sOp
era
tori
nbe
twe
en“St
ruc
tur
ena
me”&“me
mbe
rna
me”
Li
veEx
amp
le:
#i
ncl
ude
<st
dio
.h>
1
28
s
tru
ctVe
hic
le
i
ntwhe
els
;
c
harv
name
[20]
;
c
harc
olo
r[1
0];
}
v1={
4,"
Nan
o",
"Re
d"}
;
i
ntma
in(
)
p
rin
tf(
"Ve
hic
leNoo
fWhe
els:
%d"
,v1
.whe
els
);
p
rin
tf(
"Ve
hic
leNa
me :%s
",v
1.v
name
);
p
rin
tf(
"Ve
hic
leCo
lor :%s
",v
1.c
olo
r);
r
etu
rn(
0);
Ou
tpu
t:
Ve
hic
leNoo
fWhe
els:4
Ve
hic
leNa
me :
Nan
o
Ve
hic
leCo
lor :Re
d
No
te:
Do
top
era
torha
sHi
ghe
stPr
ior
ityt
hanu
nar
y,a
rit
hme
ti
c,r
ela
tio
nal
,lo
gic
alOp
era
tor
s
I
ni
ti
al
izi
ngAr
rayo
fSt
ruc
tur
einCPr
ogr
ammi
ng
Ar
raye
leme
ntsa
res
tor
edi
nco
nse
cut
iveme
mor
yLo
cat
io
n.
Li
keAr
ray,Ar
rayo
fSt
ruc
tur
eca
nbei
ni
ti
al
iz
eda
tco
mpi
let
ime
.
Wa
y1:I
ni
ti
al
iz
ingAft
erDe
cla
rin
gSt
ruc
tur
eAr
ray:
1
29
s
tru
ctBo
ok
c
harb
name
[20]
;
i
ntp
age
s;
c
hara
utho
r[20]
;
fl
oatp
ric
e;
}
b1[
3]={
{
"Le
tusC"
,700,
"YPK"
,300.
00}
,
{
"Wi
ngso
fFi
re"
,500,
"APJAb
dulKa
lam"
,350.
00}
,
{
"Co
mpl
eteC"
,1200,
"He
rbtSc
hil
dt"
,450.
00}
}
;
Ex
pla
nat
io
n:
Asso
onasafte
rdecl
arati
onofstru
ctureweini
ti
ali
zes
tru
ctur
ewiththepre
-defi
nedval
ues
.Fo
r
ea
chstr
uctu
revar
iabl
ewes pe
cifyse
tofv al
uesi
ncurl
ybrac
es.Suppo
sewehave3Ar ra
y
El
ement
sthenwehavetoin
iti
al
izeeac
ha rr
ayeleme
nti
ndi
vid
uall
yandalli
ndi
vi
dualse
tsare
co
mbin
edtoformsi
ngleset
.
{
"Le
tusC"
,700,
"YPK"
,300.
00}
Ab
oves
eto
fva
lue
sar
eus
edt
oin
iti
al
iz
efi
rste
leme
nto
fthea
rra
y.Si
mil
arl
y–
{
"Wi
ngso
fFi
re"
,500,
"APJAb
dulKa
lam"
,350.
00}
i
sus
edt
oin
iti
al
iz
ese
con
del
eme
nto
fthea
rra
y.
Wa
y2:I
ni
ti
al
iz
ingi
nMa
in
s
tru
ctBo
ok
c
harb
name
[20]
;
i
ntp
age
s;
c
hara
utho
r[20]
;
1
30
fl
oatp
ric
e;
}
;
v
oidma
in(
)
s
tru
ctBo
okb
1[3]={
{
"Le
tusC"
,700,
"YPK"
,300.
00}
,
{
"Wi
ngso
fFi
re"
,500,
"Ab
dulKa
lam"
,350.
00}
,
{
"Co
mpl
eteC"
,1200,
"He
rbtSc
hil
dt"
,450.
00}
}
;
So
meOb
ser
vat
ion
san
dImp
ort
antPo
int
s:
Ti
p#1:Al
lSt
ruc
tur
eMe
mbe
rsn
eedn
otb
ein
iti
al
iz
ed
#i
ncl
ude
<st
dio
.h>
s
tru
ctBo
ok
c
harb
name
[20]
;
i
ntp
age
s;
c
hara
utho
r[20]
;
fl
oatp
ric
e;
}
b1[
3]={
{
"Bo
ok1
",7
00,
"YPK"
},
{
"Bo
ok2"
,500,
"AAK"
,350.
00}
,
{
"Bo
ok3"
,120,
"HST"
,450.
00}
}
;
1
31
v
oidma
in(
)
p
rin
tf(
"\
nBo
okNa
me :
%s"
,b1
[0]
.bn
ame
);
p
rin
tf(
"\
nBo
okPa
ges:%d
",b
1[0]
.pa
ges
);
p
rin
tf(
"\
nBo
okAu
tho
r:%s
",b
1[0]
.au
tho
r);
p
rin
tf(
"\
nBo
okPr
ice:
%f"
,b1
[0]
.pr
ice
);
Ou
tpu
t:
Bo
okNa
me :Bo
ok1
Bo
okPa
ges:7
00Bo
ok
Au
tho
r:YPKBo
ok
Pr
ice:0.
000000
Ex
pla
nat
io
n:
I
nthi
sexampl
e,Whi lei
ni
tia
liz
ingfirstel
ementofthearra
yweha v
enotspe
cifi
edthepri
ceof
b
ook1.
Itisno
tmandat
orytoprov
ideini
tia
li
zati
onforallt
hevalu
es.Suppo
sewehave5s t
ruct
ure
e
leme
ntsandwepro
vid
eini
tia
lvaluesforfir
sttwoelemen
tthenwecann
otpro
videi
ni
t i
alva
lue
sto
r
emai
ningel
emen
ts.
{
"Bo
ok1
",7
00,
,90.
00}
a
bov
ein
iti
al
iz
ati
oni
sil
le
gala
ndc
anc
aus
eco
mpi
let
imee
rro
r.
Ti
p#2:De
fau
ltI
ni
ti
alVa
lue
s
tru
ctBo
ok
c
harb
name
[20]
;
i
ntp
age
s;
1
32
c
hara
utho
r[20]
;
fl
oatp
ric
e;
}
b1[
3]={
{
},
{
"Bo
ok2"
,500,
"AAK"
,350.
00}
,
{
"Bo
ok3"
,120,
"HST"
,450.
00}
}
;
Ou
tpu
t:
Bo
okNa
me :
Bo
okPa
ges:0
Bo
okAu
tho
r:
Bo
okPr
ice:0.
000000
I
tisc
lea
rfr
oma
bov
eou
tpu
t,De
fau
ltv
alu
esfo
rdi
ffe
ren
tda
tat
ype
s.
Da
taTy
pe De
fau
ltI
ni
ti
al
iza
tio
nVa
lue
I
nte
ger 0
Fl
oat 0.
0000
Cha
rac
ter Bl
ank
Pa
ssi
ngAr
rayo
fSt
ruc
tur
etoFu
nct
ioni
nC Pr
ogr
ammi
ng
Ar
rayo
fSt
ruc
tur
eca
nbep
ass
edt
ofu
nct
iona
saPa
rame
ter
.
Fu
nct
io
nca
nal
sor
etu
rnSt
ruc
tur
easr
etu
rnt
ype
.
St
ruc
tur
eca
nbep
ass
eda
sfo
ll
ow
Li
veEx
amp
le:
1
33
#i
ncl
ude
<st
dio
.h>
#i
ncl
ude
<co
nio
.h>
//
s
tru
ctEx
amp
le
i
ntn
um1
;
i
ntn
um2;
}
s[3]
;
//
v
oida
cce
pt(
str
uctEx
amp
les
ptr
[],
intn
)
i
nti
;
fo
r(i
=0;
i<n
;i++)
p
rin
tf(
"\
nEn
tern
um1:"
);
s
can
f("
%d"
,&s
ptr
[i]
.nu
m1)
;
p
rin
tf(
"\
nEn
tern
um2:"
);
s
can
f("
%d"
,&s
ptr
[i]
.nu
m2)
;
//
v
oidp
rin
t(s
tru
ctEx
amp
les
ptr
[],
intn
)
i
nti
;
fo
r(i
=0;
i<n
;i++)
1
34
{
p
rin
tf(
"\
nNu
m1:
%d"
,sp
tr[
i].
num1
);
p
rin
tf(
"\
nNu
m2:
%d"
,sp
tr[
i].
num2)
;
//
v
oidma
in(
)
i
nti
;
c
lrs
cr(
);
a
cce
pt(
s,3)
;
p
rin
t(s
,3)
;
ge
tch(
);
Ou
tpu
t:
En
tern
um1:1
0
En
tern
um2:2
0
En
tern
um1:3
0
En
tern
um2:4
0
En
tern
um1:5
0
En
tern
um2:6
0
Nu
m1:1
0
Nu
m2:
20
Nu
m1:
30
Nu
m2:
40
1
35
Nu
m1:
50
Nu
m2:
60
Ex
pla
nat
io
n:
I
nsi
dema
ins
tru
ctu
rea
nds
izeo
fst
ruc
tur
ear
rayi
spa
sse
d.
Whe
nre
fer
enc
e(i
.ea
mpe
rsa
nd)i
sno
tsp
eci
fi
edi
nma
in,s
othi
spa
ssi
ngi
ssi
mpl
epa
ssb
yva
lue
.El
eme
nts
c
anb
eac
ces
sedb
yus
ingd
ot[
.]o
per
ato
r
Po
int
erWi
thi
nSt
ruc
tur
einCPr
ogr
ammi
ng:St
ruc
tur
e
ma
yco
nta
int
hePo
int
erv
ari
abl
easme
mbe
r.Po
int
ersa
re
u
sedt
ost
oret
hea
ddr
esso
fme
mor
ylo
cat
io
n.The
yca
nbe
de-
r
efe
ren
ced
by„
*‟o
per
ato
r.
Ex
amp
le:
s
tru
ctSa
mpl
e
i
nt*
ptr
;//St
ore
sad
dre
sso
fin
tege
rVa
ria
ble
c
har*
name
;//St
ore
sad
dre
sso
fCha
rac
ter
Str
ing
}
s1;
s
1iss
tru
ctu
rev
ari
abl
ewhi
chi
sus
edt
oac
ces
sthe“s
tru
ctu
reme
mbe
rs”.
s
1.p
tr=&n
um;
s
1.n
ame="
Pri
te
sh"
He
renumi
san
yva
ria
bleb
uti
t‘
sad
dre
ssi
sst
ore
dint
heSt
ruc
tur
eme
mbe
rpt
r(Po
int
ert
o
I
nte
ger
)
Si
mil
arl
ySt
art
inga
ddr
esso
ftheSt
rin
g―Pr
ite
sh‖i
sst
ore
dins
tru
ctu
rev
ari
abl
ena
me(
Poi
nte
rto
Char
act
era
rra
y)
Whene
verwene
edt
opr
intt
hec
ont
ento
fva
ria
blen
um,wea
red
ere
fer
anc
ingt
hep
oin
ter
v
ari
abl
enum.
1
36
p
rin
tf(
"Co
nte
nto
fNu
m:%d"
,*s
1.p
tr)
;pr
int
f("
Name
:%s
",s
1.n
ame
);
Li
veEx
amp
le:Po
int
erWi
thi
nSt
ruc
tur
e
#i
ncl
ude
<st
dio
.h>
s
tru
ctSt
ude
nt
i
nt*
ptr
;//St
ore
sad
dre
sso
fin
tege
rVa
ria
ble
c
har*
name
;//St
ore
sad
dre
sso
fCha
rac
terSt
rin
g
}
s1;
i
ntma
in(
)
i
ntr
oll=20;
s
1.p
tr=&r
oll
;
s
1.n
ame="
Pri
te
sh"
;
p
rin
tf(
"\
nRo
llNu
mbe
rofSt
ude
nt:
%d"
,*s
1.p
tr)
;
p
rin
tf(
"\
nNa
meo
fSt
ude
nt :
%s"
,s1
.na
me)
;
r
etu
rn(
0);
Ou
tpu
t:
Ro
llNu
mbe
rofSt
ude
nt:20
1
37
Na
meo
fSt
ude
nt :Pr
ite
sh
So
meI
mpo
rta
ntOb
ser
vat
io
ns:
p
rin
tf(
"\
nRo
llNu
mbe
rofSt
ude
nt:%d
",*
s1
.pt
r);
Wehav
esto
redt
headdr
essofvar
iab
le‗
rol
l‘i
napoi
nte
rmembe
rofs
tru
ctu
ret
huswec
ana
cce
ss
v
alu
eofpo
int
ermemb
erdire
ctl
yusi
ngde
-re
fere
nceo
pera
tor
.
p
rin
tf(
"\
nNa
meo
fSt
ude
nt :%s
",s
1.n
ame
);
Si
mil
arl
ywehaves
tor
edtheb
asea
ddre
ssofs
tri
ngtopoi
nte
rva
ria
ble‗
name
‘.I
nor
dert
ode
-
re
fer
enceas
tri
ngwenev
erus
ede-
refe
ren
ceop
erat
or.
Ar
rayo
fSt
ruc
tur
e:
St
ruc
tur
eisus
edt
osto
ret
heinfo
rma
tio
nofOn
epa
rti
cul
aro
bje
ctb
uti
fwen
eedt
ost
ores
uch
1
00obj
ect
sthe
nArra
yofStr
uctu
rei
sused
.
Ex
amp
le:
s
tru
ctBo
oki
nfo
c
har
[20]b
name
;
i
ntp
age
s;
i
ntp
ric
e;
}
Boo
k[1
00]
;
Ex
pla
nat
io
n:
He
reBo
oks
tru
ctu
rei
sus
edt
oSt
oret
hei
nfo
rma
tio
nofo
neBo
ok.
I
nca
sei
fwen
eedt
ost
oret
heI
nfo
rma
tio
nof1
00b
ookst
henAr
rayo
fSt
ruc
tur
eisu
sed
.
b
1[0]s
tor
estheIn
for
ma t
io
nof1s
tBook,b
1[1
]st
ore
sthei
nfo
rma
tio
nof2n
dBo
oka
ndSoo
nWe
c
ansto
rethein
forma
tio
nof100boo
ks.
b
ook[
3]i
ssho
wnBe
low
1
38
Ac
ces
si
ngPa
gesfi
el
dofSe
con
dBo
ok:
Bo
ok[
1].
page
s
Li
veEx
amp
le:
#i
ncl
ude<
std
io.
h>
s
tru
ctBo
oki
nfo
c
har
[20]b
name
;
i
ntp
age
s;
i
ntp
ric
e;
}
boo
k[3]
;
i
ntma
in(
in
tar
gc,c
har*
argv
[])
i
nti
;
fo
r(i
=0;
i<3;
i++)
p
rin
tf(
"\
nEn
tert
heNa
meo
fBo
ok :"
);
ge
ts(
boo
k[i
].b
name
);
p
rin
tf(
"\
nEn
tert
heNu
mbe
rofPa
ges:"
);
1
39
s
can
f("
%d"
,bo
ok[
i].
page
s);
p
rin
tf(
"\
nEn
tert
hePr
iceo
fBo
ok:"
);
s
can
f("
%f"
,bo
ok[
i].
pri
ce)
;
p
rin
tf(
"\
n--
---
---
-Bo
okDe
tai
ls "
);
fo
r(i
=0;
i<3;
i++)
p
rin
tf(
"\
nNa
meo
f Bo
ok : %s
",b
ook[
i].
bna
me)
;
p
rin
tf(
"\
nNu
mbe
rofPa
ges:%d
",b
ook[
i].
page
s);
p
rin
tf(
"\
nPr
iceo
fBo
ok:%f"
,bo
ok[
i].
pri
ce)
;
r
etu
rn0;
Ou
tpu
toft
heSt
ruc
tur
eEx
amp
le:
En
tert
heNa
meo
fBo
ok:ABC
En
tert
heNu
mbe
rofPa
ges:1
00
En
tert
hePr
iceo
fBo
ok200
En
tert
heNa
meo
fBo
ok:EFG
En
tert
heNu
mbe
rofPa
ges:200
En
tert
hePr
iceo
fBo
ok300
En
tert
heNa
meo
fBo
ok :HI
J
En
tert
heNu
mbe
rofPa
ges:30
0
En
tert
hePr
ice
ofBo
ok 500
Bo
okDe
tai
ls
1
40
Na
meo
fBo
ok :ABC
Nu
mbe
rofPa
ges:1
00
Pr
iceo
fBo
ok :200
Na
meo
fBo
ok :EFG
Nu
mbe
rofPa
ges:200
Pr
iceo
fBo
ok :300
Na
meo
fBo
ok :HI
J
Nu
mbe
rofPa
ges:300
Pr
iceo
fBo
ok:500Un
ion
i
nCPr
ogr
ammi
ng:
I
nCProgra
mmingwehaveca
meacro
ssSt
ruc
tur
es.Uni
onsar
esi
mil
ar
t
ost
ruc
tur
esyn
tact
ic
all
y.Sy
ntaxo
fb o
thi
sal
mostsi
mil
ar.Letu
sdi
scu
sss
omei
mpo
rta
ntp
oin
tso
ne
b
yone–
No
te#1:Un
iona
ndSt
ruc
tur
ear
eAl
mos
tSi
mil
ar
u
nio
nst
ud s
tru
cts
tud
{ {
i
ntr
oll
; i
ntr
oll
;
c
harn
ame
[4]
; c
harn
ame
[4]
;
i
ntma
rks
; i
ntma
rks
;
}
s1; }
s1;
I
fwelo
okatt
het
woe
xamp
lest
henwec
ans
ayt
hatb
oths
tru
ctu
rea
ndu
nio
nar
esa
mee
xce
pt
Ke
ywo
rd.
No
te#2:Mu
lti
pl
eMe
mbe
rsa
reCo
ll
ect
edTo
get
herUn
derSa
meNa
me
i
ntr
oll
;
c
harn
ame
[4]
;
1
41
i
ntma
rks
;
Weha
vec
oll
ect
edt
hre
eva
ria
ble
sofd
iffe
ren
tda
tat
ypeu
nde
rsa
men
amet
oge
the
r.No
te
#3:Al
lUn
ionMe
mbe
rsOc
cup
ySa
meMe
mor
yAr
ea
Fortheuni
onmaxi
mumme
moryall
oca
tedwil
lbee
qua
ltot
hedat
amembe
rwi
thmax
imums
ize
.Inthe
ex
amp l
echara
cte
rarr
ay‗
name‘hav
ema x
imumsi
zet
husmax
imummemo
ryo
ftheu
nio
nwi
llbe4
Byte
s.
Ma
ximu
mMe
mor
yofUn
ion=Ma
ximu
mMe
mor
yofUn
ionDa
ta
Me
mbe
r
No
te#4:On
lyo
neMe
mbe
rwi
llb
eac
ti
vea
tat
ime
.
Su
ppo
sewea r
ea c
ces
si
ngo n
eo fthedat
amemb e
ro funi
onthenwecan
notac
ces
sot
herd
ata
me
mbersi
ncewecanacc
esss
ingl
edatamemb
erofu ni
onbec
aus
eeachd
atamembe
rsha
res
same
me
mory.ByUsi
ngUni
onwecanSaveLoto
fVa l
uabl
eSpac
e
Si
mpl
eEx
amp
le:
u
nio
nu
c
hara
;
i
ntb
;
Ho
wtoDe
cla
reUn
ioni
nC?
Uni
onissi
mil
artothatofSt
ruc
ture
.Synt
axo
fbo
tha
res
ameb
utma
jord
iffe
ren
ceb
etwe
en
st
ruc
tureandun
ionis‗memo
ryst
orage
‗.
1
42
I
nst
ruct
ures
,eachmembe
rhasi
tso
wnst
ora
gel
oca
tio
n,whe
rea
sal
ltheme
mbe
rso
fun
ionu
set
he
s
amelo
cati
on.Un
ionc
ont
ain
sman
ymemb
erso
fdi
ffer
entt
ype
s,
Un
ionc
anha
ndl
eon
lyo
neme
mbe
ratat
ime
.
Sy
nta
x:
u
nio
nta
g
u
nio
n_me
mbe
r1;
u
nio
n_me
mbe
r2;
u
nio
n_me
mbe
r3;
.
.
.
.
.
.
u
nio
n_me
mbe
rN;
}
ins
tan
ce;
No
te:
Un
ion
sar
eDe
cla
redi
nthes
amewa
yasaSt
ruc
tur
e.On
ly―s
tru
ctKe
ywo
rd‖i
sre
pla
cedwi
thu
nio
n
Sa
mpl
eDe
cla
rat
io
nofUn
ion:
u
nio
nst
ud
i
ntr
oll
;
c
harn
ame
[4]
;
i
ntma
rks
;
}
s1;
<
1
43
Ho
wMe
mor
yisAl
lo
cat
ed?
SoFr
omt
heAb
ovefi
g.Wec
anCo
ncl
ude–
Un
ionMe
mbe
rst
hatc
omp
oseau
nio
n,a
lls
har
ethes
ames
tor
agea
reawi
thi
nthec
omp
ute
rsme
mor
y
Ea
chme
mbe
rwi
thi
nas
tru
ctu
rei
sas
si
gne
dit
sownu
niq
ues
tor
agea
rea
Thu
sun
ion
sar
eus
edt
oob
ser
veme
mor
y.
Uni
onsar
euse
fu lfo
rap
pli
cati
onin
volv
ingmul
ti
pleme
mbe
rs,whe
rev
alu
esn
eedn
otb
e
as
si
gnedtoa
llthememb
ersatanyonet
ime.
CPr
ogr
ammi
nga
cce
ssi
ngu
nio
nme
mbe
rs
Whil
eac
ces
sin
gu n
ion
,weca
nhaveac
ces
stos
ingl
eda
tame
mbe
ratat
ime
.wec
ana
cce
sss
ingl
eun
ion
me
mberus
ingfol
lo
wingt
woOpe
rato
rs–
Us
ingDOTOp
era
tor
1
44
Us
ingARROW Op
era
tor
Ac
ces
si
ngu
nio
nme
mbe
rsDOTo
per
ato
r
I
norde
rtoa
cce
sst
hemembe
roftheun
ionweareu
sin
gthedo
top
era
tor.DOTo
per
ato
risu
sedi
nsi
de
p
rin
tfands
can
fst
ate
mentt
oget
/setv
aluefr
om/ofuni
onme
mbe
rloc
atio
n.
Sy
nta
x:
v
ari
abl
e_n
ame
.me
mbe
r
co
nsi
dert
hebel
owun
ion
,whenwed
ecl
areav
ari
abl
eofu
nio
nty
pet
henwewi
llb
eac
ces
si
ngu
nio
n
membe
rsusi
ngdo
top
erat
or.
u
nio
nemp
i
nti
d;
c
harn
ame
[20]
;
}
e1;
i
dca
nbeAc
ces
sedb
y–u
nio
n_v
ari
abl
e.me
mbe
r
Sy
nta
x Ex
pla
nat
ion
e
1.i
d Ac
ces
sidfi
el
dofu
nio
n
e
1.n
ame Ac
ces
sna
mefi
el
dofu
nio
n
Ac
ces
sin
gun
ionme
mbe
rsAr
rowo
per
ato
r
I
nst
eadofma
int
aint
heuni
onv
ari
abl
esup
posewest
oreu
nio
na tp
arti
cul
aradd
res
sthe
nwec
an
a
cces
stheme
mbersoft
heuni
onus
ingp
oin
tertot
heuni
onandarr
owopera
tor
.
u
nio
nemp
i
nti
d;
c
harn
ame
[20]
;
}
*e1
;
1
45
i
dca
nbeAc
ces
sedb
y–u
nio
n_v
ari
abl
e->
memb
er
Sy
nta
x Ex
pla
nat
ion
e
1->
id Ac
ces
sidfi
el
dofu
nio
n
e
1->
name Ac
ces
sna
mefi
el
dofu
nio
n
CPr
ogr
ams
Pr
ogr
am#1:Us
ingd
oto
per
ato
r
#i
ncl
ude<
std
io.
h>
u
nio
nemp
i
nti
d;
c
harn
ame
[20]
;
}
e1;
i
ntma
in(
in
tar
gc,c
har*
argv
[])
e
1.i
d=1
0;
p
rin
tf(
"\
nID:%d
",e
1.i
d)
;
s
trc
py(
e1
.na
me,
"Pr
ite
sh"
);
p
rin
tf(
"\
nNa
me:%s
",e
1.n
ame
);
r
etu
rn0;
Ou
tpu
t:
I
D:1
0
Na
me:Pr
ite
sh
Pr
ogr
am#2:Ac
ces
si
ngs
ameme
mor
y
1
46
#i
ncl
ude<
std
io.
h>
u
nio
nemp
i
nti
d;
c
harn
ame
[20]
;
}
e1;
i
ntma
in(
in
tar
gc,c
har*
argv
[])
e
1.i
d=1
0;
s
trc
py(
e1
.na
me,
"Pr
ite
sh"
);
p
rin
tf(
"\
nID:%d
",e
1.i
d)
;
p
rin
tf(
"\
nNa
me:%s
",e
1.n
ame
);
r
etu
rn0;
Ou
tpu
t:
I
D:1
953067
600
Na
me:Pr
ite
sh
Aswealr
ead
ydis
cus
sedi
nthepre
vio
usar
tic
leo
fun
ionb
asi
cs,weha
ves
eenho
wme
mor
yiss
har
edb
y
al
lun
ionfi
el
ds.I
ntheab
oveex
ample–
To
talme
mor
yfo
run
ion=ma
x(s
ize
of(
id
),s
ize
of(
name
))
=s
ize
of(
name
)
=20b
yte
s
Fi
rst
lywehaveu
til
iz
edfirs
ttwobyt
esouto
f20b y
tesfo
rstor
ingi
nte
gerval
ue.Afte
rexec
uti
ono
f
st
ate
mentaga
ins
amememoryisov
err
idd
enbycha
ract
erarra
ysowhi
lepri
nti
ngtheIDval
ue,
gar
bageva
luege
tspri
nte
d
Pr
ogr
am#3:Us
inga
rro
wop
era
tor
1
47
#i
ncl
ude<
std
io.
h>
u
nio
nemp
i
nti
d;
c
harn
ame
[20]
;
}
*e1
;
i
ntma
in(
in
tar
gc,c
har*
argv
[])
e
1->
id=1
0;
p
rin
tf(
"\
nID:%d
",e
1->
id)
;
s
trc
py(
e1
->n
ame
,"Pr
ite
sh"
);
p
rin
tf(
"\
nNa
me:%s
",e
1->
name
);
r
etu
rn0;
Ou
tpu
t:
I
D:1
0
Na
me:Pr
it
esh
Bi
tfi
el
s:
Supp
osey
ourCpro
gra
mco
nta
insan
umb
ero
fTRUE/FALSEv
ari
abl
esgr
oup
edi
nas
tru
ctu
rec
all
ed
st
atus
,asfol
lo
ws−
s
tru
ct{
u
nsi
gne
din
twi
dthVa
li
dat
ed;
u
nsi
gne
din
the
ight
Val
id
ate
d;
}s
tat
us;
1
48
Thi
sst
ruc
tur
erequi
res8byt
eso
fme mo
ryspa
cebutina
ctu
al,wea
regoi
ngt
ost
oreei
the
r0or1i
n
eac
hofthevari
abl
es.TheCprogr
ammin
glangu
a geo
ffersabe
tte
rwaytou
til
iz
etheme
mo r
y
spa
cei
nsu
chsi
tua
tio
ns.
I
fyouareus
ings
uchva
riab
lesi
nsi
deas
tru
ctu
rethenyo
ucandefi
nethewid
thofava
ria
b l
ewhic
h
t
ell
stheCcompi
le
rtha
tyouaregoi
ngt
ouseonl
ythos
enumbe
ro fby
t e
s.Fore
xamp
le,theab
ove
s
truc
turec
anbere-
wri
tte
nasfoll
ows−
s
tru
ct{
u
nsi
gne
din
twi
dthVa
li
dat
ed:1
;
u
nsi
gne
din
the
ight
Val
id
ate
d:1
;
}s
tat
us;
Theabo
vestr
uctu
rerequ
ire
s4b
yte
sofme
mor
ysp
acefo
rst
atu
sva
ria
ble
,bu
ton
ly2b
itswi
llb
e
use
dtosto
retheval
ues
.
I
fyo
uwillus
eupto32va
ria
blesea
chonewi
thawidthof1bi
t,the
nalsothest
atusst
ruct
urewi
ll
u
se4by
tes.Howe
vera
ssoo
na syo
uhave33vari
abl
es,i
twil
lall
oca
tethenexts
lotofthememor
y
a
ndi
twil
lstar
tusi
ng8byt
es.Letusc
heckthefol
lo
wingex
ampletou
n d
erst
andtheconc
ept−
#i
ncl
ude<
std
io.
h>
#i
ncl
ude<
str
ing.
h>
/*d
efi
nes
imp
les
tru
ctu
re*
/
s
tru
ct{
u
nsi
gne
din
twi
dthVa
li
dat
ed;
u
nsi
gne
din
the
ight
Val
id
ate
d;
}s
tat
us1
;
/*d
efi
neas
tru
ctu
rewi
thb
itfi
el
ds*
/
s
tru
ct{
u
nsi
gne
din
twi
dthVa
li
dat
ed:1
;
1
49
u
nsi
gne
din
the
ight
Val
id
ate
d:1
;
}s
tat
us2;
i
ntma
in(){
p
rin
tf("
Memo
rys
izeo
ccu
pie
dbys
tat
us1:%d
\n"
,si
zeo
f(s
tat
us1
))
;
p
rin
tf("
Memo
rys
izeo
ccu
pie
dbys
tat
us2:%d
\n"
,si
zeo
f(s
tat
us2)
);
r
etu
rn0;
Whe
nthea
bov
eco
dei
sco
mpi
le
dan
dex
ecu
ted
,itp
rod
uce
sthefo
ll
owi
ngr
esu
lt−
Me
mor
ysi
zeo
ccu
pie
dbys
tat
us1:
8
Me
mor
ysi
zeo
ccu
pie
dbys
tat
us2:
4
Bi
tFi
el
dDe
cla
rat
ion
Thed
ecl
ara
tio
nofab
it-
fie
ldha
sthefo
ll
owi
ngfo
rmi
nsi
deas
tru
ctu
re−
s
tru
ct{
t
ype[
memb
er_n
ame
]:wi
dth;
}
;
Thefo
ll
owi
ngt
abl
ede
scr
ibe
sthev
ari
abl
eel
eme
ntso
fab
itfi
el
d−
El
eme
nts De
scr
ipt
ion
t
ype Anin
tege
rtyp
ethatd
ete
rmi
neshowabit
-fi
el
d'
sva
luei
sin
ter
pre
ted
.
Thety
pemaybei
nt,s
ign
edi
nt,orun
sign
edi
nt.
me
mbe
r_n
ame Then
ameo
ftheb
it-
fie
ld.
wi
dth Thenumb
erofbi
tsi
nthebi
t-fi
eld
.Thewi
dthmu
stb
ele
sst
hano
req
ualt
o
theb
itwi
dthoft
hespec
ifi
edty
pe.
Thev a
ria
blesde
fin
edwit
hapred
efi
nedwidt
ha r
eca
lle
dbi
tfie
lds
.Abi
tfi
eldca
nhol
dmor
ethan
asi
n gl
eb i
t;forex
ample
,ify
ounee
dav ar
iabl
etos
tor
eaval
uefro
m0to7
,t he
nyo
ucand
efi
ne
abitfiel
dwithawidt
hof3bit
sasfol
lows−
1
50
s
tru
ct{
u
nsi
gne
din
tage:3;
}Age
;
Theab
ovest
ru c
tur
edefi
nit
io
nins
tru
ctst
heCcompi
le
rthatt
heageva
riab
lei
sgo
ingtous
eonl
y3
bi
tst
ostor
et heva
lue.I
fyoutr
ytousemor
ethan3bi
ts
,theni
twil
lnotal
lo
wyoutodos
o.Letu
s
tr
ythefol
lowingexa
mple−
#i
ncl
ude<
std
io.
h>
#i
ncl
ude<
str
ing.
h>
s
tru
ct{
u
nsi
gne
din
tage:3;
}Age
;
i
ntma
in(){Age
.age
=
4;
p
rin
tf("
Siz
eof(Age):%d
\n"
,si
zeo
f(Age
))
;
p
rin
tf("
Age
.age:%d
\n"
,Age
.age)
;
Age
.age=
7;
p
rin
tf("
Age
.age:%d
\n"
,Age
.age)
;
Age
.age=
8;
p
rin
tf("
Age
.age:%d
\n"
,Age
.age)
;
r
etu
rn0;
Whent
heab
oveco
dei
sco
mpi
le
ditwi
llc
omp
il
ewi
thawa
rni
nga
ndwhe
nex
ecu
ted
,itp
rod
uce
sthe
fo
ll
owi
ngr
esul
t−
Si
zeo
f(Age):4
Age
.age:
4
Age
.age:
7
1
51
Age
.age:0
Ty
ped
ef:
TheCpro
gra
mmingl
angu
agepro
vide
sakey
wordca
lle
dty
ped
ef,whi
chyo
ucanus
etogi
veat
ype
,
anewn
ame.Fol
lo
win
gisanex
ampletod
efi
neate
rmBYTEforo
ne-
byt
enumb
ers−
t
ype
defu
nsi
gne
dcha
rBYTE;
Afte
rthi
stypedefin
iti
on,t
hei
den
tifi
erBYTEc
anb
eus
eda
sana
bbr
evi
ati
onfo
rthe
ty
peunsi
gne
dc ha
r ,forexa
mpl
e..
BYTEb
1,b
2;
Byc
onv
ent
io
n,upp
erc
asel
ett
ersa
reus
edfort
hes
ede
fin
iti
onst
oremi
ndt
heu
sert
hatt
het
ypen
ame
i
sre
all
yasymb
oli
cab
brev
iat
io
n,buty
ouca
nusel
owe
rca
se,asfol
lo
ws−
t
ype
defu
nsi
gne
dcha
rby
te;
Youc
anu s
etyped
eftogiveanametoy
ouru
serd
efin
eddat
aty
pesaswel
l.Fore
xampl
e,yo
uca
n
us
etype
defwithstr
uctu
retodefi
neanewd
atat
ypeandt
henu
sethatd
ataty
petode
fin
e
st
ruc
turevar
iab
lesdi
rec
tlyasfol
lo
ws−
#i
ncl
ude<
std
io.
h>#i
ncl
ude
<
str
ing.
h>t
ype
defs
tru
ct
Bo
oks{
c
hart
it
le[
50]
;
c
hara
utho
r[50]
;
c
hars
ubj
ect
[1
00]
;
i
ntb
ook_i
d;
}Bo
ok;
i
ntma
in()
{Bo
okb
ook;
s
trc
py(b
ook.
tit
le,"
CPr
ogr
ammi
ng"
);
s
trc
py(b
ook.
aut
hor
,"Nu
haAl
i"
);
s
trc
py(b
ook.
sub
jec
t,"
CPr
ogr
ammi
ngTu
tor
ial
")
;
1
52
b
ook.
boo
k_i
d=64
954
07;
p
rin
tf("
Boo
kti
tl
e:%s
\n"
,bo
ok.
tit
le)
;
p
rin
tf("
Boo
kau
tho
r:%s
\n"
,bo
ok.
aut
hor
);
p
rin
tf("
Boo
ksu
bje
ct:%s
\n"
,bo
ok.
sub
jec
t);
p
rin
tf("
Boo
kbo
ok_i
d:%d
\n"
,bo
ok.
boo
k_i
d)
;
r
etu
rn0;
Whe
nthea
bov
eco
dei
sco
mpi
le
dan
dex
ecu
ted
,itp
rod
uce
sthefo
ll
owi
ngr
esu
lt−Bo
ok
t
it
le:CPr
ogr
ammi
ng
Bo
oka
utho
r:Nu
haAl
i
Bo
oks
ubj
ect:CPr
ogr
ammi
ngTu
tor
ialBo
ok
b
ook_i
d:6
4954
07
t
ype
defv
s#d
efi
ne
#de
fin
eisaC-
dir
ecti
vewhic
hisa
lsous
edtod
efi
net
hea
li
ase
sfo
rva
rio
usd
atat
ype
ssi
mil
art
o
ty
pede
fbutwi
ththefol
lowi
ngdi
ffer
ence
s−
ty
p e
defisl
imi
te
dtogiv
ings
ymb
oli
cnamest
oty
peson
lywhe
rea
s#d
efi
nec
anb
eus
edt
ode
fin
eal
ia
s
forval
uesa
swell
,q.,youc
and
efi
ne1asONEetc
.
t
ype
defin
ter
pret
ati
oni
spe
rfo
rme
dbyt
hec
omp
il
erwhe
rea
s#d
efi
nes
tat
eme
ntsa
rep
roc
ess
edb
ythe
p
re-
proc
ess
or.
Thefo
ll
owi
nge
xamp
les
howsho
wtou
se#d
efi
nei
nap
rogr
am−
#i
ncl
ude<
std
io.
h>
#d
efi
neTRUE1
#d
efi
neFALSE0
i
ntma
in(){
p
rin
tf("
Val
ueo
fTRUE:%d
\n"
,TRUE)
;
p
rin
tf("
Val
ueo
fFALSE:%d
\n"
,FALSE)
;
1
53
r
etu
rn0;
Whe
nthea
bov
eco
dei
sco
mpi
le
dan
dex
ecu
ted
,itp
rod
uce
sthefo
ll
owi
ngr
esu
lt−
Va
lueo
fTRUE:1
Va
lueo
fFALSE:0
En
ume
rat
edd
atat
ype
:
Anen
umera
tio
nisaus
er-
defi
neddat
aty
pecon
sis
tsofi
nte
gralc
ons
tan
tsa
nde
achi
nte
gra
lco
nst
anti
s
gi
veana
me.Ke y
wor
denumisuse
dtode
fin
edenume
rat
eddat
atype
.
e
numt
ype
_na
me{v
alu
e1,v
alu
e2,
...
,va
lue
N};
Her
e,ty
pe_nameist
hena
meo
fen
ume
rat
edd
atat
ypeo
rta
g.An
dva
lue
1,v
alu
e2,
. v
,al
ueNa
re
va
lue
softyet
p y
pe_na
me.
Byde
fau
lt,va
lue
1wi
llb
eeq
ua o0,v
lt alu
e2wi
llb
e1a
nds
oonb
ut,t
hep
rogr
amme
rca
ncha
nget
he
de
fau
ltva
lue
.
//Cha
ngi
ngt
hed
efa
ultv
alu
eofe
nume
leme
ntse
num
s
uit
{
c
lub
=0;
d
iamo
nds
=10;
he
art
s=20;
s
pad
es=
3;
}
;
De
cla
rat
iono
fen
ume
rat
edv
ari
abl
e
Abov
ecodede
fin
esthetyp
eoft
hed
atab
ut,n
oan
yva
ria
blei
scr
eat
ed.Va
ria
bleo
fty
pe
en
umc a
nb ec
rea
tedas:
e
num
b
ool
ean
{fa
ls
e
;
1
54
t
rue
;
1
55
}
;
e
numb
ool
eanc
hec
k;
He
re,av
ari
abl
eche
cki
sde
cla
redwhi
chi
soft
ypee
numb
ool
ean
.
Ex
amp
leo
fen
ume
rat
edt
ype
#i
ncl
ude<
std
io.
h>
e
numwe
ek{s
und
ay,mo
nda
y,t
ues
day
,we
dne
sda
y,t
hur
sda
y,fr
ida
y,s
atu
rda
y};i
nt
ma
in(
){
e
numwe
ekt
oda
y;
t
oda
y=we
dne
sda
y;
p
rin
tf(
"%d
day
",t
oda
y+1
);
r
etu
rn0;
Ou
tpu
t
4d
ay
Yo
ucanwri
tea
nypro
gra
minClan
guagewi
thou
tthehe
lpo
fen
ume
rat
io
nsb
ut,e
nume
rat
io
nshe
lpsi
n
wr
iti
ngc
lea
rcode
san
dsi
mpl
ifyp
rogr
a mmi
ng.
Dy
nami
cme
mor
yal
loc
ati
on
Theexac
tsizeo
fa rr
ayisunknownu nt
il
lthecompil
eti
me,i
.e.,t
imewhenacompie
rcompi
lescod
e
wri
tteni
nap ro
gramminglanguageint
oae x
ecutab
lefor
m.Thesizeofar
rayyouhavedec
lare
d
i
nit
ial
lycanbesomet
ime
sinsuffici
entandso
metimesmor
ethanre
quir
ed.Dyn
amicmemoryall
ocat
ion
al
lowsaprogra
mt oobt
ainmo r
eme moryspa
ce,whiler
unni
ngortorel
eas
espacewhennospac
eis
req
uir
ed.
Al
tho
ugh,Cla
nguagei
nhere
ntl
ydoesno
thasan
ytec
hniq
uetoal
loc
atedme
mor
ydy
nami
cal
ly,t
her
e
ar
e4li
brar
yfunc
ti
onsund
er"st
dli
b.h"ford
yna
micmemorya
llo
cat
ion
.
Fu
nct
io
n Us
eofFu
nct
io
n
1
56
Fu
nct
io
n Us
eofFu
nct
io
n
ma
llo
c() Al
lo
cat
esr
equ
est
eds
izeo
fby
tesa
ndr
etu
rnsap
oin
terfi
rstb
yteo
fal
lo
cat
eds
pac
e
Al
lo
cat
ess
pac
efo
rana
rra
yel
eme
nts
,in
iti
al
iz
est
oze
roa
ndt
henr
etu
rnsap
oin
tert
o
c
all
oc(
)
me
mory
fr
ee(
) d
ell
oca
tet
hep
rev
iou
slya
llo
cat
eds
pac
e
r
eal
lo
c() Cha
nget
hes
izeo
fpr
evi
ous
lya
llo
cat
eds
pac
e
ma
llo
c()
Thena
memal
lo
cstan
dsfo
r"me
morya
llo
cat
io
n".Thefun
ctio
nma
llo
c()
res
erve
sabl
ockof
memor
yofs
peci
fi
edsi
zea
ndre
tur
napoi
nte
roftypevo
idwhi
chc
anbecas
tedin
top
oin
tero
fan
y
for
m.
Sy
nta
xofma
llo
c()
p
tr=
(ca
st-
typ
e*)
mal
lo
c(b
yte
-si
ze)
He
re,pt
risp
oin
terofc
ast-
typ
e.Themall
oc(
)fun
cti
onre
turn
sap o
int
ertoana
reao
fmemory
wi
thsi
zeofb
ytesi
ze.I
fthesp
acei
sin
suffi
ci
ent
,all
oca
tio
nfail
sandret
urn
sNULLpoi
nte
r.
p
tr=
(i
nt*
)ma
llo
c(1
00*
si
zeo
f(i
nt)
);
Thisst
ate
mentwi
llal
lo
catee
it
her200o
r4 00ac
cord
ingt
osiz
eofi
nt2o
r4b
yte
sre
spe
cti
vel
y
andthepo
int
erpo
int
stotheadd
res
soffi
rstby
teofmemor
y.
c
all
oc(
)
Then
amecal
locs
tandsfor"
con
tiguo
u sa
llo
cati
on"
.Theonl
ydi
ffere
ncebet
wee
nmall
oc(
)andc
all
oc(
)
i
stha
t,mall
oc(
)all
ocat
essi
ngl
eb l
ockofmemorywhere
ascal
lo
c()a
llo
cat
esmul
ti
pl
eblo
cksof
memo
ryea
chofs a
mes i
zean
dsetsallby
testozer
o.
Sy
nta
xofc
all
oc(
)
p
tr=
(ca
st-
typ
e*)
cal
lo
c(n
,el
eme
nt-
siz
e);
Thi
sst
ate
men
twi
lla
llo
cat
eco
nti
guo
uss
pac
einme
mor
yfo
rana
rra
yofn
ele
men
ts.Fo
rex
amp
le:
p
tr=
(fl
oat
*)
cal
lo
c(25,
siz
eof(
flo
at)
);
1
57
Thi
sst
ate
menta
llo
cat
esc
ont
igu
ouss
pac
einme
mor
yfo
rana
rra
yof25e
leme
ntse
acho
fsi
zeo
ffl
oat
,
i
.e,4byt
es.
fr
ee(
)
Dyna
mica
llya
llo
cat
edmemo
rywit
heit
herc
all
oc(
)ormal
lo
c()d
oesn
otge
tre
tur
noni
tso
wn.The
pr
ogrammermustu
sefr
ee(
)ex
pli
ci
tl
ytore
lea
sespa
ce.
s
ynt
axo
ffr
ee(
)
fr
ee(
ptr
);
Thi
sst
ate
men
tca
uset
hes
pac
einme
mor
ypo
int
erb
ypt
rtob
ede
all
oca
ted
.
Ex
amp
leso
fca
llo
c()a
ndma
llo
c()
Wri
teaCp r
ogramt
ofindsumofnel
eme
ntse
nte
redb
yus
er.Top
erfo
rmt
hisp
rogr
am,a
llo
cat
eme
mor
y
d
yna
mica
llyus
ingma
llo
c()fu
nct
io
n.
#i
ncl
ude <
std
io.
h>
#i
ncl
ude<
std
li
b.h>
i
ntma
in(
){
i
ntn
,i,
*pt
r,s
um=
0;
p
rin
tf(
"En
tern
umb
ero
fel
eme
nts
:")
;
s
can
f("
%d"
,&n
);
p
tr=
(i
nt*
)ma
llo
c(n
*si
zeo
f(i
nt)
);//me
mor
yal
lo
cat
edu
sin
gma
llo
c
i
f(p
tr=
=NULL)
p
rin
tf(
"Er
ror
!me
mor
yno
tal
lo
cat
ed.
");
e
xit
(0)
;
p
rin
tf(
"En
tere
leme
ntso
far
ray
:")
;
fo
r(i
=0;
i<n
;++i
)
1
58
s
can
f("
%d"
,pt
r+i
);
s
um+=
*(p
tr+i
);
p
rin
tf(
"Su
m=%d
",s
um)
;
fr
ee(
ptr
);
r
etu
rn0;
Wri
teaCprogr
amtofinds
umo fnel
ement
sen
ter
edb
yus
er.Top
erfo
rmt
hisp
rogr
am,
all
oca
te
me
moryd
yna
mica
llyu
sin
gcal
lo
c()
fun
cti
on.
#i
ncl
ude <
std
io.
h>
#i
ncl
ude<
std
li
b.h>
i
ntma
in(
){
i
ntn
,i,
*pt
r,s
um=
0;
p
rin
tf(
"En
tern
umb
ero
fel
eme
nts
:")
;
s
can
f("
%d"
,&n
);
p
tr=
(i
nt*
)c
all
oc(
n,s
ize
of(
in
t))
;
i
f(p
tr=
=NULL)
p
rin
tf(
"Er
ror
!me
mor
yno
tal
lo
cat
ed.
");
e
xit
(0)
;
p
rin
tf(
"En
tere
leme
ntso
far
ray
:")
;
fo
r(i
=0;
i<n
;++i
)
s
can
f("
%d"
,pt
r+i
);
1
59
s
um+=
*(p
tr+i
);
p
rin
tf(
"Su
m=%d
",s
um)
;
fr
ee(
ptr
);
r
etu
rn0;
r
eal
lo
c()
I
ft hepr
evi
ous
lyal
lo
cat
edmemor
yisin
suffi
ci
ento
rmo
ret
hans
uffi
ci
ent
.The
n,y
ouc
anc
han
ge
memorysi
zepr
evi
ous
lyal
lo
cat
edusi
ngreal
lo
c()
.
Sy
nta
xofr
eal
lo
c()
p
tr=
rea
llo
c(p
tr,
news
ize
);
He
re,p
tri
sre
all
oca
tedwi
ths
izeo
fne
wsi
ze.
#i
ncl
ude<
std
io.
h>
#i
ncl
ude<
std
li
b.h>
i
ntma
in(
){
i
nt*
ptr
,i,
n1,
n2;
p
rin
tf(
"En
ters
izeo
far
ray
:")
;
s
can
f("
%d"
,&n
1)
;
p
tr=
(i
nt*
)ma
llo
c(n
1*
si
zeo
f(i
nt)
);
p
rin
tf(
"Ad
dre
sso
fpr
evi
ous
lya
llo
cat
edme
mor
y:"
);
fo
r(i
=0;
i<n
1;++i
)
p
rin
tf(
"%u
\t"
,pt
r+i
);
p
rin
tf(
"\
nEn
tern
ews
izeo
far
ray
:")
;
s
can
f("
%d"
,&n
2);p
tr=
rea
llo
c(p
tr,
n2)
;
1
60
fo
r(i
=0;
i<n
2;++i
)
p
rin
tf(
"%u
\t"
,pt
r+i
);
r
etu
rn0;
1
61
UNI
T-
I
VFI
LES
DRAWBACKSOFTRADI
TIONALI
/OSYSTEM
Un
tiln
owwea
reu
sin
gCo
nso
leOr
ien
tedI
/Ofu
nct
io
ns.
―Co
nso
leAp
pli
cat
ion‖me
ansa
nap
pli
cat
io
ntha
tha
sat
ext
-ba
sedi
nte
rfa
ce.(
bla
cks
cre
enwi
ndo
w))
Mo
sta
ppl
ic
ati
onsr
equ
ireal
argea
mou
nto
fda
ta,i
fthi
sda
tai
sen
ter
edt
hro
ughc
ons
olet
hen
i
twi
llb
equ
itet
imec
ons
umi
ngt
ask
Ma
ind
rawb
acko
fus
ingTr
adi
ti
ona
lI/O:
-da
tai
ste
mpo
rar
y(a
ndwi
lln
otb
eav
ail
abl
edu
rin
gre
-
e
xec
uti
on)
Co
nsi
dere
xamp
le–
Weha
vewr
itt
enCPr
ogr
amt
oac
cep
tpe
rso
nde
tai
lfr
omu
sera
ndwea
rego
ingt
opr
intt
hes
ede
tai
ls
b
ackt
othes
cre
en.
No
wco
nsi
dera
not
hers
cen
ari
o,s
upp
osewewa
ntt
opr
ints
amed
atat
hatweha
vee
nte
red
pre
vio
usl
y.
Wec
ann
ots
aved
atawhi
chwa
sen
ter
edo
nthec
ons
oleb
efo
re.
No
wwea
res
tor
ingd
atae
nte
red(
dur
ingfi
rstr
un)i
ntot
extfi
lea
ndwhe
nwen
eedt
hisd
atab
ack
(
dur
ing2n
dru
n),wea
rego
ingt
ore
adf
ile
.
1
62
I
ntr
odu
cti
ont
ofi
leha
ndl
ingi
nC
Ne
wwa
yofd
eal
in
gwi
thd
atai
sfi
leha
ndl
in
g.
Da
tai
sst
ore
don
tot
hed
iska
ndc
anb
ere
tri
evewhe
nev
err
equ
ire
.
Ou
tpu
toft
hep
rogr
amma
ybes
tor
edo
ntot
hed
isk
I
nCweha
vema
nyfu
nct
io
nst
hatd
eal
swi
thfi
leha
ndl
in
g
Afi
lei
sac
oll
ect
io
nofb
yte
sst
ore
donas
eco
nda
rys
tor
aged
evi
ce(
gen
era
llyad
isk)
Co
ll
ect
io
nofb
ytema
ybei
nte
rpr
ete
das–
Si
ngl
echa
rac
ter
Si
ngl
eWo
rd
Si
ngl
eLi
ne
Co
mpl
eteSt
ruc
tur
e.
Fi
leI
/OSt
rea
msi
nCPr
ogr
ammi
ngLa
ngu
age
I
nCa
lli
npu
tan
dou
tpu
tisd
onewi
ths
tre
amsSt
rea
m
i
sno
thi
ngb
utt
hes
equ
enc
eofb
yte
sofd
ata
As
equ
enc
eofb
yte
sfl
owi
ngi
ntop
rogr
ami
sca
lle
din
puts
tre
am
As
equ
enc
eofb
yte
sfl
owi
ngo
uto
fthep
rogr
ami
sca
lle
dou
tpu
tst
rea
m
Us
eofSt
rea
mma
keI
/Oma
chi
nei
nde
pen
den
t.
Pr
ede
fin
edSt
rea
ms:
s
tdi
n St
and
ardI
npu
t
s
tdo
ut St
and
ardOu
tpu
t
1
63
s
tdi
n St
and
ardI
npu
t
s
tde
rr St
and
ardEr
ror
St
and
ardI
npu
tSt
rea
mDe
vic
e
s
tdi
nst
and
sfo
r(St
and
ardI
npu
t)
Ke
ybo
ardi
sst
and
ardi
npu
tde
vic
e.
St
and
ardi
npu
tisd
ata(
Oft
enTe
xt)go
ingi
ntoap
rogr
am.
Thep
rogr
amr
equ
est
sda
tat
ran
sfe
rsb
yus
eoft
her
eado
per
ati
on.
No
tal
lpr
ogr
amsr
equ
irei
npu
t.
St
and
ardOu
tpu
tSt
rea
mDe
vic
e
s
tdo
uts
tan
dsfo
r(St
and
ardOu
tpu
t)Sc
ree
n(Mo
nit
or)
i
sst
and
ardo
utp
utd
evi
ce.
St
and
ardo
utp
uti
sda
ta(
Oft
enTe
xt)go
ingo
utfr
omap
rogr
am.The
p
rogr
ams
end
sda
tat
oou
tpu
tde
vic
ebyu
sin
gwr
iteo
per
ati
on.
Di
ffe
ren
ceBe
twe
enSt
d.I
npu
tan
dOu
tpu
tSt
rea
mDe
vic
es:
Po
int St
di/pSt
rea
mDe
vic
e St
and
ardo
/pSt
rea
mDe
vic
e
St
and
s
St
and
ardI
npu
t St
and
ardOu
tpu
t
Fo
r
Ex
amp
le Ke
ybo
ard Sc
ree
n/Mo
nit
or
1
64
Po
int St
di/pSt
rea
mDe
vic
e St
and
ardo
/pSt
rea
mDe
vic
e
Da
ta(
Oft
enTe
xt)go
ingi
ntoa d
ata(
Oft
enTe
xt)go
ingo
utfr
oma
Da
taFl
ow
p
rogr
am p
rogr
am
Op
era
tio
n Re
adOp
era
tio
n Wr
iteOp
era
tio
n
So
meI
mpo
rta
ntSu
mma
ry:
Po
int I
npu
tSt
rea
m Ou
tpu
tSt
rea
m
St
and
ardDe
vic
e1 Ke
ybo
ard Sc
ree
n
St
and
ardDe
vic
e2 Sc
ann
er Pr
int
er
I
OFu
nct
io
n s
can
fan
dge
ts p
rin
tfa
ndp
uts
I
OOp
era
tio
n Re
ad Wr
ite
Da
ta Da
tago
esfr
oms
tre
am d
atac
ome
sin
tos
tre
am
Te
xtfi
leFo
rma
tinCPr
ogr
ammi
ng
Te
xtFi
le
isAl
soCa
lle
das
―Fl
atFi
le
―.
Te
xtFi
leFo
rma
tisBa
sicFi
leFo
rma
tinCPr
ogr
ammi
ng.
Te
xtFi
lei
ssi
mpl
eSe
que
nceo
fASCI
ICha
rac
ter
s.
Ea
chLi
nei
sCha
rac
ter
ize
dbyEOLCha
rac
ter(
Endo
fLi
ne)
.
1
65
Te
xtFi
leFo
rma
ts
Te
xtFi
leha
ve.
txtEx
ten
sio
n.
Te
xtFi
leFo
rma
tha
veLi
tt
lec
ont
ain
sve
ryl
it
tlefo
rma
tti
ng.
Thep
rec
ised
efi
ni
ti
ono
fthe.
txtfo
rma
tisn
ots
pec
ifi
ed,b
utt
ypi
cal
lyma
tche
sthefo
rma
t
a
cce
pte
dbyt
hes
yst
emt
ermi
nalo
rsi
mpl
ete
xte
dit
or.
Fi
le
swi
tht
he.
txte
xte
nsi
onc
ane
asi
lyb
ere
ado
rop
ene
dbya
nyp
rogr
amt
hatr
ead
ste
xta
nd,fo
r
t
hatr
eas
on,a
rec
ons
ide
redu
niv
ers
al(
orp
lat
for
min
dep
end
ent
).
Te
xtFo
rma
tCo
nta
inMo
stl
yEn
gli
shCha
rac
ter
s
Wha
tar
eBi
nar
yFi
le
s
Bi
nar
yFi
le
sCo
nta
inI
nfo
rma
tio
nCo
dedMo
stl
yinBi
nar
yFo
rma
t.Bi
nar
y
Fi
le
sar
edi
ffi
cul
ttor
eadfo
rhu
man
.
Bi
nar
yFi
le
sca
nbep
roc
ess
edb
yce
rta
ina
ppl
ic
ati
onso
rpr
oce
sso
rs.
On
lyBi
nar
yFi
lePr
oce
sso
rsc
anu
nde
rst
oodCo
mpl
exFo
rma
tti
ngI
nfo
rma
tio
nSt
ore
dinBi
nar
y
Fo
rma
t.
Hu
man
sca
nre
adb
ina
ryfi
le
son
lya
fte
rpr
oce
ssi
ng.
Al
lEx
ecu
tab
leFi
le
sar
eBi
nar
yFi
le
s.
Ex
pla
nat
io
n:
Ass
howni
nfi
g.Bi
nar
yfi
lei
sst
ore
dinBi
nar
yFo
rma
t(i
n0/1
).Thi
sBi
nar
yfi
lei
sdi
ffi
cul
ttor
ead
fo
rhu
man
s.Soge
ner
all
yBi
nar
yfi
lei
sgi
vena
sin
putt
otheBi
nar
yfi
lePr
oce
sso
r.Pr
oce
sso
rwi
ll
c
onv
ertb
ina
ryfi
lei
ntoe
qui
val
entr
ead
abl
efi
le
.
So
meEx
amp
leso
ftheBi
nar
yfi
le
s:
Ex
ecu
tab
leFi
le
s
Da
tab
asef
ile
s
1
66
Be
for
eop
eni
ngt
hefi
lewemu
stu
nde
rst
andt
heb
asi
cco
nce
pto
ffi
lei
nCPr
ogr
ammi
ng,Ty
pes
of
Fi
le
.Ifwewa
ntt
odi
spl
ays
omeme
ssa
geo
nthec
ons
olefr
omt
hefi
let
henwemu
sto
peni
ti
n
r
ead
mod
e.
Op
eni
nga
ndDe
fin
ingFI
LEi
nCPr
ogr
ammi
ng
Be
for
est
ori
ngd
atao
ntot
hes
eco
nda
rys
tor
age,fi
rst
lywemu
sts
pec
ifyfo
ll
owi
ngt
hin
gs–
Fi
len
ame
Da
taSt
ruc
tur
e
Pe
rpo
se/Mo
de
Ve
ryfi
rstt
aski
nFi
leha
ndl
in
gist
oop
enfi
le
Fi
len
ame:Sp
eci
fi
esNa
meo
ftheFi
le
Fi
len
amec
ons
is
tso
ftwofi
el
ds
Fi
rstfi
el
disn
amefi
el
dan
dse
con
dfi
el
diso
fex
ten
sio
nfi
el
d
Ex
ten
sio
nfi
el
diso
pti
ona
l
Bo
thFi
len
amea
nde
xte
nsi
ona
res
epa
rat
edb
ype
rio
dord
ot.
Da
taSt
ruc
tur
e
Da
tas
tru
ctu
reo
ffi
lei
sde
fin
eda
sFI
LEi
nthel
ibr
aryo
fst
and
ardI
/Ofu
nct
io
ns
I
nsho
rtweha
vet
ode
cla
ret
hep
oin
terv
ari
abl
eoft
ypeFI
LE
Mo
deo
fFI
LEo
pen
ing
I
nCPr
ogr
ammi
ngwec
ano
penfi
lei
ndi
ffe
ren
tmo
dess
ucha
sre
adi
ngmo
de,
wri
ti
ngmo
dea
nda
ppe
ndi
ng
mo
ded
epe
ndi
ngo
npu
rpo
seo
fha
ndl
in
gfi
le
.
Fo
ll
owi
nga
ret
hed
iffe
ren
tOp
eni
ngmo
deso
fFi
le:
1
67
Op
eni
ng Pr
evi
ousDa
ta
Pu
rpo
se
Mo
de
Re
adi
ng Fi
lewi
llb
eop
ene
dju
stfo
rre
adi
ngp
urp
ose Re
tai
ned
Wr
iti
ng Fi
lewi
llb
eop
ene
dju
stfo
rwr
iti
ngp
urp
ose Fl
ushe
d
Fi
lewi
llb
eop
ene
dfo
rap
pen
din
gso
met
hin
ginfi
le
Ap
pen
din
g Re
tai
ned
Di
ffe
ren
tSt
epst
oOp
enFi
le
St
ep1:De
cla
rin
gFI
LEp
oin
ter
Fi
rst
lywen
eedp
oin
terv
ari
abl
ewhi
chc
anp
oin
ttofi
le
.be
lowi
sthes
ynt
axfo
rde
cla
rin
gthe
fi
le
poi
nte
r.
FI
LE*
fp;
St
ep2:Op
eni
ngfi
lehe
ll
o.t
xt
fp=fo
pen
("fi
le
name
","
mod
e")
;
L
ive
Exa
mpl
e:Op
eni
ngt
heFi
l
ean
dDe
fi
ni
ngt
heFi
l
e#i
ncl
ude
<st
dio
.h>
i
n tma
in(
)
{
FILE*fp
;
charc
h;
fp=fo
pen
("I
NPUT.
txt
","
r")//Op
enfi
lei
nRe
admo
de
fc
los
e(fp
);//Cl
oseFi
lea
fte
rRe
adi
ng
r
etu
rn(
0);
}
I
fwewanttoo
penfi
lei
ndi
ffe
ren
tmo
det
henfo
ll
owi
ngs
ynt
axwi
llb
eus
ed–
Re
adi
ngMo
de fp=fo
pen
("he
ll
o.t
xt"
,"r
");
Wr
iti
ngMo
de fp=fo
pen
("he
ll
o.t
xt"
,"w"
);
Ap
pen
dMo
de fp=fo
pen
("he
ll
o.t
xt"
,"a
");
1
68
Op
eni
ngt
heFi
l
e:Ye
tAn
ot
her
Liv
eEx
amp
le#i
ncl
ude
<st
dio
.h>
v
oidmai
n(
)
{
FILE*
fp;
charc
h;
fp=fopen
("I
NPUT.
txt
","
r")
;//Op
enfi
lei
nRe
admo
de
whil
e(
1)
{
ch=fgetc(
fp)
;//ReadaChar
act
er
if(
ch= =EOF)//Chec
kforEndofFi
le
bre
ak;
pri
ntf(
"%c"
,ch)
;
}
fcl
ose
(fp);//Clos
eFi
lea
fte
rRe
adi
ng
}
Fi
leOpeni
ngMo d
eChar
t
fo
penRe
tur
nsi
fFI
LE-
Mo
de Me
ani
ng
Ex
ist
s No
tEx
ist
s
r Re
adi
ng – NULL
Cr
eat
eNe
w
w Wr
iti
ng Ov
erwr
iteo
nEx
ist
ing
Fi
le
Cr
eat
eNe
w
a Ap
pen
d –
Fi
le
Re
adi
ng+ Ne
wda
tai
swr
itt
ena
ttheb
egi
nni
ng Cr
eat
eNe
w
r
+
Wr
iti
ng o
ver
wri
ti
nge
xis
ti
ngd
ata Fi
le
Re
adi
ng+ Cr
eat
eNe
w
w+ Ov
erwr
iteo
nEx
ist
ing
Wr
iti
ng Fi
le
a
+ Re
adi
ng+ Ne
wda
tai
sap
pen
deda
tthee
ndo
ffi
le Cr
eat
eNe
w
1
69
Ap
pen
din
g Fi
le
Ex
pla
nat
io
n:
Fi
lec
anb
eop
ene
dinb
asi
c3mo
des:Re
adi
ngMo
de,Wr
iti
ngMo
de,Ap
pen
din
gMo
de
I
fFi
lei
sno
tpr
ese
nto
nthep
aths
pec
ifi
edt
henNe
wFi
lec
anb
ecr
eat
edu
sin
gWr
itea
nd
Ap
pen
dMo
de.
Ge
ner
all
yweu
sedt
oop
enfo
llo
win
gty
peso
ffi
lei
nC–
Fi
leTy
pe Ex
ten
sio
n
CSo
urc
eFi
le .
c
Te
xtFi
le .
txt
Da
taFi
le .
dat
Wr
iti
ngo
nthefi
lewi
llo
ver
wri
tep
rev
iou
sco
nte
nt
EOFa
ndfe
offu
nct
io
n>>s
tdi
o.h>
>Fi
leHa
ndl
in
ginC
Sy
nta
x:
i
ntfe
of(
FILE*
str
eam)
;
Wha
titd
oes
?
Ma
crot
est
sife
nd-
of-
fil
eha
sbe
enr
eac
hedo
nas
tre
am.
fe
ofi
sama
crot
hatt
est
sthegi
vens
tre
amfo
rane
nd-
of-
fil
ein
dic
ato
r.
On
cet
hei
ndi
cat
ori
sse
t,r
eado
per
ati
onso
nthefi
ler
etu
rnt
hei
ndi
cat
oru
nti
lre
win
disc
all
ed,o
r
t
hefi
lei
scl
ose
d.
Thee
nd-
of-
fil
ein
dic
ato
risr
ese
twi
the
achi
npu
top
era
tio
n.
Wa
yso
fDe
tec
tin
gEn
dofFi
le
A]I
nTe
xtFi
le:
Sp
eci
alCha
rac
terEOFd
eno
test
hee
ndo
fFi
le
Ass
oona
sCha
rac
teri
sre
ad,
Endo
ftheFi
lec
anb
ede
tec
ted
1
70
EOFi
sde
fin
edi
nst
dio
.h
Eq
uiv
ale
ntv
alu
eofEOFi
s-1
Pr
int
ingVa
lueo
fEOF:
v
oidma
in(
)
{
p
rin
tf(
"%d
",EOF)
;
}
B]I
nBi
nar
yFi
le:
fe
offu
nct
io
nisu
sedt
ode
tec
tthee
ndo
ffi
le
I
tca
nbeu
sedi
nte
xtfi
le
fe
ofRe
tur
nsTRUEi
fen
doffi
lei
sre
ache
d
Sy
nta
x:
i
ntfe
of(
FILE*
fp)
;
Wa
yso
fWr
iti
ngfe
ofFu
nct
io
n:
Wa
y1:I
nifs
tat
eme
nt:
i
f(fe
of(
fpt
r)=
=1)//a
sif(
1)i
sTRUE
p
rin
tf(
"En
dofFi
le
")
;
Wa
y2:I
nWhi
leLo
op
whi
le
(!fe
of(
fpt
r))
{
-
---
--
-
---
--
}
C-Co
mma
ndLi
neAr
gume
nts
mai
n(
)fun
cti
ono
faCp r
ogr
amac
cep
tsa
rgu
men
tsfr
omc
omma
ndl
in
eorfr
omo
the
rshe
lls
cri
pts
b
yfol
lo
wingco
mmand
s.The
yare
,
a
rgc
a
rgv
[]
whe
re,
1
71
a
rgc –Numb e
rofargu
mentsi
nthec
omman
dli
nei
ncl
udi
ngp
rogr
amn
ame
a
rgv
[]–Thi
siscar
ryi
ngal
lthear
gumen
ts
I
nre
alt
imea
p p
li
cati
on,i
twi
llhap
pentop
assar
gument
stothemai
npro
gra
mit
sel
f.The
se
a
rgu
ment
sarepas
sedtot
hemain(
)fun
cti
onwhi
leex
ecut
ingbi
nar
yfil
efro
mco
mma n
dli
ne.
Fo
rex
amp
le,whe
nwec
omp
il
eap
rogr
am(
tes
t.c
),wege
tex
ecu
tab
lefi
lei
nthen
ame―t
est
‖.No
w,
wer
unt
hee
xec
uta
ble―t
est
‖al
ongwi
th4a
rgu
men
tsi
nco
mma
ndl
in
eli
keb
elo
w.
.
/te
stt
hisi
sap
rogr
am
Whe
re,
a
rgc = 5
a
rgv
[0] = ―test‖
a
rgv
[1] = ―t
his‖
a
rgv
[2] = ―is
‖
a
rgv
[3] = ―a‖
a
rgv
[4] = ―program‖
a
rgv
[5] = NULL
EXAMPLEPROGRAMFORARGC(
)ANDARGV(
)FUNCTI
ONSI
NC:
#i
ncl
ude<
std
io.
h>
#i
ncl
ude<
std
li
b.h>
i
ntma
in(
in
tar
gc,c
har*
argv
[])//c
omma
ndl
in
ear
gume
nts
i
f(a
rgc
!=5)
p
rin
tf(
"Ar
gume
ntsp
ass
edt
hro
ughc
omma
ndl
in
e"\
"
note
qua
lto5"
);
r
etu
rn1
;
1
72
p
rin
tf(
"\
nPr
ogr
amn
ame:%s\
n",a
rgv
[0]
);
p
rin
tf(
"1
sta
rg:%s\
n",a
rgv
[1]
);
p
rin
tf(
"2n
dar
g:%s\
n",a
rgv
[2]
);
p
rin
tf(
"3r
dar
g:%s\
n",a
rgv
[3]
);
p
rin
tf(
"4t
har
g:%s\
n",a
rgv
[4]
);
p
rin
tf(
"5t
har
g:%s\
n",
argv
[5]
);
r
etu
rn0;
}OUTPUT:
Programname:tes
t
1
sta r
g:t hi
s
2ndarg:
i
s3r darg
:a
4t
ha rg:p ro
gram
5t
ha rg:( n
ull
)
1
73