Fyit PPC Unit1
Fyit PPC Unit1
sanAl
gor
it
hm?
Apr ogrammingalgor
it
hm is
apr ocedureorformul
ausedf orsol
vi
ngapr obl
em.Iti
sbasedon
conduct i
ngasequenceofspecifiedactionsi
nwhichtheseacti
onsdescri
behowt odosomet
hing,
andy ourcomputerwil
ldoitexact l
ythatwayever
ytime.Analgori
thm worksbyf
ollowi
nga
procedure,madeupofinputs.
Theadv
ant
agesof
pr
ogr
ammi
ngal
gor
it
hmsi
ncl
ude:
● Ast
epwi
ser
epr
esent
ati
onofasol
uti
ont
oagi
venpr
obl
em,
maki
ngi
teasyt
ounder
stand.
● Usesadef
ini
tepr
ocedur
e.
● Notdependentonapar
ti
cul
arpr
ogr
ammi
ngl
anguage.
● Ev
eryst
epi
nanal
gor
it
hm hasi
tsownl
ogi
cal
sequence,
maki
ngi
teasyt
odebug.
I
ncomputerprogr
ammi ngt
erms,analgori
thm i
sasetofwell
-def
inedi
nstr
ucti
onst
osol
vea
par
ti
cul
arprobl
em.Itt
akesasetofinput(
s)andproducest
hedesiredout
put.
Qual
i
tiesofaGoodAl
gor
it
hm
I
nputandout
putshoul
dbedef
inedpr
eci
sel
y.
Eachst
epi
ntheal
gor
it
hm shoul
dbecl
earandunambi
guous.
Al
gor
it
hmsshoul
dbemostef
fect
iveamongmanydi
ff
erentway
stosol
veapr
obl
em.
Anal
gori
thm shoul
dn'
ti
ncl
udecomputercode.I
nst
ead,thealgor
it
hm shoul
dbewr
it
teni
nsuch
awaythati
tcanbeusedindi
ff
erentpr
ogramminglanguages.
Al
gor
it
hm 1:
Addt
wonumber
sent
eredbyt
heuser
St
ep1:
Star
t
St
ep2:
Decl
arev
ari
abl
esnum1,
num2andsum.
St
ep3:
Readv
aluesnum1andnum2.
St
ep4:
Addnum1andnum2andassi
gnt
her
esul
ttosum.
sum←num1+num2
St
ep5:
Displ
aysum
St
ep6:
Stop
Al
gor
it
hm 2:
Findt
hel
argestnumberamongt
hreenumber
s
St
ep1:
Star
t
St
ep2:
Decl
arev
ari
abl
esa,
bandc.
St
ep3:
Readv
ari
abl
esa,
bandc.
St
ep4:
Ifa>b
I
fa>c
Di
spl
ayai
sthel
argestnumber
.
El
se
Di
spl
ayci
sthel
argestnumber
.
El
se
I
fb>c
Di
spl
aybi
sthel
argestnumber
.
El
se
Di
spl
ayci
sthegr
eat
estnumber
.
St
ep5:
Stop
Al
gor
it
hm 3:
Findt
hef
act
ori
alofanumber
St
ep1:
Star
t
St
ep2:
Decl
arev
ari
abl
esn,
fact
ori
alandi
.
St
ep3:
Ini
ti
ali
zev
ari
abl
es
f
act
ori
al←1
i
←1
St
ep4:
Readv
alueofn
St
ep5:
Repeatt
hest
epsunt
ili
=n
5.
1:f
act
ori
al←f
act
ori
al*
i
5.
2:i
←i+1
St
ep6:
Displ
ayf
act
ori
al
St
ep7:
Stop
Al
gor
it
hm 4:
Checkwhet
heranumberi
spr
imeornot
St
ep1:
Star
t
St
ep2:
Decl
arev
ari
abl
esn,
i,f
lag.
St
ep3:
Ini
ti
ali
zev
ari
abl
es
f
lag← 1
i
←2
St
ep4:
Readnf
rom t
heuser
.
St
ep5:
Repeatt
hest
epsunt
ili
=(n/
2)
5.
1Ifr
emai
nderofn÷i
equal
s0
f
lag← 0
Got
ost
ep6
5.
2i←i
+1
St
ep6:
Iff
lag=0
Di
spl
ayni
snotpr
ime
el
se
Di
spl
ayni
spr
ime
St
ep7:
Stop
Al
gor
it
hm 5:
Findt
heFi
bonacci
ser
iest
il
lthet
erml
esst
han1000
St
ep1:
Star
t
St
ep2:
Decl
arev
ari
abl
esf
ir
st_
ter
m,second_
ter
m andt
emp.
St
ep3:
Ini
ti
ali
zev
ari
abl
esf
ir
st_
ter
m ← 0second_
ter
m← 1
St
ep4:
Displ
ayf
ir
st_
ter
m andsecond_
ter
m
St
ep5:
Repeatt
hest
epsunt
ilsecond_
ter
m ≤1000
5.
1:t
emp← second_
ter
m
5.
2:second_
ter
m ← second_
ter
m +f
ir
st_
ter
m
5.
3:f
ir
st_
ter
m← t
emp
5.
4:Di
spl
aysecond_
ter
m
St
ep6:
Stop
Hi
stor
yofCl
anguage?
· Ci soneoft hehigh-lev elpr ogr
ammi nglanguagesdev el
opedbyDenni sRi t
chie.
· Cwasor iginall
ydev elopedf orUNI Xoper ati
ngsy st
em tobeatt heissuesofpr eviouslanguages
suchasB, BCPL, etc.
· TheUNI Xoper ati
ngsy stem dev elopmentst art
edi ntheyear1969,andi tscodewasr ewri
tt
eni nC
i
nt heyear1972.
· In1985, Wi ndows1. 0wasr el
eased.Ev ent houghWi ndowssour cecodei sn’tpubl i
clyavail
ableon
themar ket
,it
’sbeenst atedt hati t
sker nel i
smost lywr i
tteninC.
· In1991, Linuxker nel dev elopmentst arted, andit’saddit
ional
lywrit
teni nC.
· Aft
eray earitwasr eleasedundert heGNUl i
censeandwasusedaspar toft heGNUOper ati
ng
System.
· TheGNUoper ati
ngsy stem wasst ar t
edusi ngCandLi spprogrammi nglanguages.So, manyofi ts
component sar ewr it
teninC.
· In1977, Oracledat abasedev elopmentst arted,andin1983i tscodewasr ewri
ttenf rom assembl y
toC.Itbecameonei nal l
t hef or emostwi despr eaddat abaseswi t
hinthewor l
d.
· Nowaday sCi sex clusi velyusedf orbui ldingOS,appl i
cati
onpackagesandcust omi zedsoftware.
Becauseofi t
spowerandef fici
ency ,i
thasgai nedmor epopulari
ty.
· Cisincr easinglyusedbysy stem pr ogr ammer s,appli
cati
ondev elopersandr esearcher
sf ora
spreadofprogr ammi ngtasks.
Basi
cSt
ruct
ureofCPr
ogr
am
Sect
ion Descr
ipt
ion
Document
ati
on Consi
stsoft
hedescr
ipt
ionoft
heprogram,progr
ammer'sname,
andcr
eati
ondat
e.Thesearegener
all
ywrit
teninthef
orm of
comments.
Li
nk Al
lheaderfil
esareincl
udedi
nthissect
ionwhichcont
ains
di
ff
erentfuncti
onsfrom t
hel
ibr
ari
es.Acopyoftheseheaderf
il
es
i
sinsert
edintoyourcodebef
orecompilat
ion.
Def
ini
ti
on Incl
udespreprocessordi
rect
ive,
whichcont
ainssymbol
ic
constant
s.E.g.
:#defineal
lowsustouseconstant
sinourcode.I
t
repl
acesallt
heconst ant
swithit
svaluei
nthecode.
Gl
obal
Decl
arat
ion Incl
udesdecl
arati
onofglobalvar
iabl
es,
funct
iondecl
arat
ions,
stat
icgl
obalvari
ables,
andfuncti
ons.
Mai
n()Funct
ion ForeveryCprogr
am,theexecuti
onst
art
sfrom t
hemain(
)
funct
ion.I
tismandat
orytoincl
udeamain(
)funct
ioni
never
yC
progr
am.
Subpr
ogr
ams Incl
udesalluser-
definedfunctions(f
uncti
onstheuserprovi
des).
Theycancont ai
nt heinbuil
tfuncti
ons,andthefunct
ion
defi
nit
ionsdeclaredintheGl obalDecl
arat
ionsecti
on.Theseare
call
edinthemai n()funct
ion.
Thecompi
l
ati
onofaCpr
ogr
am i
nvol
vessev
eral
steps:
Pr
epr
ocessi
ng
Thepr
eprocessorhandl
esthepr
epr
ocessordi
rect
ives,
li
ke#i
ncl
udeand#def
ine.I
tisagnost
ic
oft
hesyntaxofC,whichiswhyi
tmustbeusedwithcare.
ItworksononeCsour cefi
leatat i
mebyr epl
acing#incl
udedir
ecti
veswit
hthecontentoft
he
respecti
vef
il
es(whichisusual
lyjustdecl
arat
ions),
doingrepl
acementofmacros(#defi
ne)
,and
select
ingdi
ff
erentport
ionsoftextdependi
ngof#i f
,#if
defand#if
ndefdir
ect
ives.
Theprepr
ocessorisworkingonastream ofprepr
ocessingt
oken,andmacr
osubst
it
uti
oni
s
def
inedasrepl
acingtokensbyothertokens(t
heoperator##all
owstomerget
wotokenswhen
i
tmakesense).
Afterallt
hisitpr
oducesasingl
eoutputthati
sastream oftokensresult
ingfrom t
he
tr
ansf or
mat i
onsdescri
bedabove.I
talsoaddssomespeci almarkersthattel
lthecompil
er
wher eeachlinecamefrom sot
hatitcanusethosetoproducesensibleerrormessages.
Someer
ror
scanbepr
oducedatt
hisst
agewi
thcl
everuseoft
he#i
fand#er
rordi
rect
ives.
Compi
l
ati
on
Thecompi l
ati
onstepi sperf
ormedoneachoutputoft heprepr
ocessor.I
tinv
olvespar
singtheC
sourcecode(nowwit houtanypr
eprocessordi
rect
ives)and,pr
oducinganobjectfi
l
e.Thisobj
ect
fi
lecontai
nsthecompi ledcode(i
nbinar
yform)ofthesy mbolsdefi
nedintheinput
.Symbolsin
objectf
il
esareref
erredt obyname.
Objectfi
l
escanr efertosymbol
sthatarenotdefi
ned.Thi
sisthecasewhenyouusea
declar
ati
on,anddon' tpr
ovi
deadefini
ti
onforit
.Thecompilerdoesn'
tmi
ndthi
s,andwi
l
lhappi
l
y
producetheobjectfi
leaslongasthesourcecodeiswell
-f
ormed.
Compil
ersusuall
yletyoustopcompil
ati
onatthi
spoint.Thisi
sveryusef
ulbecausewithi
tyou
cancompileeachsourcecodefi
lesepar
atel
y.Theadvantagethi
sprovi
desisthatyoudon'
t
needtorecompil
eev er
ythi
ngifyouonl
ychangeasingl
ef i
le.
Theproducedobj
ectf
il
escanbeputi
nspeci
alar
chi
vescal
l
edst
ati
cli
brar
ies,
foreasi
err
eusi
ng
l
ateron.
It
'satthi
sstagethe"
regul
ar"compi
l
erer
ror
s,l
i
kesy
ntaxer
ror
sorf
ail
edov
erl
oadr
esol
uti
on
error
s,ar
ereport
ed.
Li
nki
ng
Thelinkeri
swhatproducest
hefinal
compi l
ati
onoutputfr
om t heobjectfi
lesthecompil
er
produced.Thi
soutputcanbeei
therashared(ordynamic)l
ibrary(andwhi l
ethenameissimil
ar,
theyhaven'
tgotmuchincommonwi thstati
cli
brar
iesmentionedear l
ier)oranexecut
able.
I
tli
nksallt
heobj ectfi
l
esbyr eplaci
ngt her
eferencestoundefinedsymbolscontai
nedwi thi
n
t
hem withthecor r
ectaddresses.Eachofthesesy mbolscanbedef i
nedinotherobjectfi
lesor
i
nli
brar
ies.Iftheyaredefi
nedi nli
brar
iesotherthanthestandardli
brar
y,y
ouneedt ot el
lthe
l
i
nkeraboutt hem.
Atthi
sstagethemostcommoner r
orsaremissingdef i
nit
ionsordupl
icatedefi
niti
ons.The
formermeansthatei
thert
hedefini
ti
onsdon'texist(
i.
e.theyarenotwr i
tt
en),orthattheobj
ect
fi
lesorl
ibr
ari
eswheretheyresi
dewerenotgi v
ent othelinker
.Thelat
terisobvious:t
hesame
symbolwasdefinedi
nt wodif
fer
entobjectf
il
esorl i
brari
es.
compi
leri
sapr
ogr
am t
hatconv
ert
shi
gh-
lev
ell
anguaget
oassembl
ylanguage.Si
mil
arl
y,
anassembl
eri
sapr
ogr
am t
hatconv
ert
stheassembl
ylanguaget
omachi
ne-
lev
el
l
anguage.
Letusf
ir
stunder
standhowapr
ogr
am,
usi
ngCcompi
l
er,
isexecut
edonahostmachi
ne.
● Userwr
it
esapr
ogr
am i
nCl
anguage(
high-
lev
ell
anguage)
.
● TheCcompi
l
er,
compi
l
est
hepr
ogr
am andt
ransl
atesi
ttoassembl
y
pr
ogr
am (
low-
lev
ell
anguage)
.
● Anassembl
ert
hent
ransl
atest
heassembl
ypr
ogr
am i
ntomachi
necode
(
obj
ect
).
● Al
i
nkert
ool
isusedt
oli
nkal
lthepar
tsoft
hepr
ogr
am t
oget
herf
or
execut
ion(
execut
abl
emachi
necode)
.
● Al
oaderl
oadsal
loft
hem i
ntomemor
yandt
hent
hepr
ogr
am i
sexecut
ed.
Li
nker
Li
nkeri
sacomput
erpr
ogr
am t
hatl
i
nksandmer
gesv
ari
ousobj
ectf
il
est
oget
heri
n
or
dert
omakeanexecut
abl
efi
l
e.Al
lthesef
il
esmi
ghthav
ebeencompi
l
edbysepar
ate
assembl
ers.The maj
or t
ask of a l
i
nker i
sto sear
ch and l
ocat
eref
erenced
modul
e/r
out
inesi
napr
ogr
am andt
odet
ermi
net
hememor
ylocat
ionwher
ethese
codeswi
l
lbel
oaded,
maki
ngt
hepr
ogr
am i
nst
ruct
iont
ohav
eabsol
uter
efer
ences.
Pr
epr
ocessor
Apr
epr
ocessor
,gener
all
yconsi
der
edasapar
tofcompi
l
er,
isat
oolt
hatpr
oducesi
nput
f
orcompi
l
ers.I
tdeal
swi
thmacr
o-pr
ocessi
ng,augment
ati
on,f
il
eincl
usi
on,l
anguage
ext
ensi
on,
etc.
PseudocodeandFl
owchar
ts
Good, l
ogi
cal pr
ogrammingisdev
elopedt
hroughgoodpr
e-code
pl
anningandorganizat
ion.Thi
sisassi
stedbyt
heuseofpseudocodeand
pr
ogram fl
owcharts.
Fl
owchartsar
ewr i
tt
enwi t
hprogram f
lowf
rom thetopofapageto
thebottom.Eachcommandi spl
acedinaboxoftheappropr
iat
eshape,
andarrowsareusedtodirectpr
ogram fl
ow.Thefol
lowingshapesar
e
oft
enusedinflowchar
ts:
● Pseudocodei nCi sasi mplewayt owr it
epr ogrammi ngcodei n
Engli
sh.Pseudocodei sani nfor
mal wr i
ti
ngst yl
ef orprogram
al
gor i
thmsindependentf rom programmi nglanguagest oshowt he
basicconceptbehindthecode.
● Pseudocodeisnotanact ualprogrammi nglanguage.Soi tcannotbe
compi l
edandnotbeconv ertedintoanexecut ableprogr am.Ituses
shortorsimpleEngli
shl anguagesy ntaxtowr it
ecodef orprograms
beforeiti
sconv er
tedintoaspeci f
icpr ogrammi nglanguage.
● Thepseudocodei nCconsi stsofwor dsandphr asesthatmake
pseudocodel ooksimilartothepr ogram butnotapr ogram.
● Thepseudo-codei sneitheranal gorit
hm norapr ogram
Pseudocodei
salsoknownasProgram Desi
gnLanguage(
PDL)or
Str
uctur
edhasthefol
lowi
ngcharact
eri
sti
cs:
● Af reesy nt axofnat urall
anguagethatdescribesaprocessing
feature.
● Asubpr ogr am def i
nit
ionandcall
ingt echni
ques.
● Fixedsy nt axofkey wor dsthatpr
ov i
def oral
lstr
uctur
ed
const ructs, datadeclarati
onsandmodul ar
it
ycharacteri
sti
cs.
● Adat adecl arationfacil
it
y.
● Pseudocodei sasetofsequent i
alwr i
ttenhumanlanguage
i
nst ructi
ons, usuall
ynumber ed,t
hatisusedt odescribethe
actionsapr ogram willt
akewheni tiscodedi naprogrammi ng
l
anguage.
Ingeneral
,herear
esomer
ulest
hatar
efr
equent
lyf
oll
owedwhenwr
it
ing
pseudocode:
● Theusual
For
transy
mbol
sar
eusedf
orar
it
hmet
icoper
ati
ons(
+,-
,*,
/
, **
).
● Symbol i
cnamesar eusedtoindi
catethequant i
ti
esbeingprocessed.
● Ce r
tai
nFor t
rankeywordscanbeused, suchasPRI NT,WRITE,READ,
etc.
● Indentat
ionshouldbeusedtoindi
catebr anchesandloopsof
i
nst r
ucti
on.
ThePseudocodeusesplai
nEngli
shstatement
srat
hert
hansy
mbol
s,t
o
presentt
heprocessesofacomputersy
stem.
Exampl
e:
Fact
ori
alofaposit
ivei
ntegerni
sproductofal
lval
uesf
rom nt
o1.For
exampl
e,thef
actori
alof3is(3*2*1=6) .
Al
gor
it
hm
START
St
ep1→ Takei
ntegerv
ari
abl
eA
St
ep2→ Assi
gnv
aluet
othev
ari
abl
e
St
ep3→ Fr
om v
alueAupt
o1mul
ti
plyeachdi
gitandst
ore
St
ep4→ t
hef
inalst
oredv
aluei
sfact
ori
alofA
STOP
Pseudocode
Wecandr
aftapseudocodeoft
heabov
eal
gor
it
hm asf
oll
ows−
pr
ocedur
efi
nd_
fact
ori
al(
number
)
FORv
alue=1t
onumber
f
act
ori
al=f
act
ori
al*v
alue
ENDFOR
DI
SPLAYf
act
ori
al
endpr
ocedur
e
Var
iabl
esi
nC
Avar
iabl
eisanameoft
hememor
ylocat
ion.I
tisusedt
ost
oredat
a.I
tsv
aluecanbe
changed,
andi
tcanber
eusedmanyt
imes.
I
tisawayt
orepr
esentmemor
ylocat
iont
hroughsy
mbol
ssot
hati
tcanbeeasi
l
y
i
dent
if
ied.
Let
'sseet
hesy
ntaxt
odecl
areav
ari
abl
e:
1.t
ypev
ari
abl
e_l
i
st;
Theex
ampl
eofdecl
ari
ngt
hev
ari
abl
eisgi
venbel
ow:
● i
nta;
● f
loatb;
● charc;
Her
e,a,
b,car
evar
iabl
es.Thei
nt,
float
,charar
ethedat
aty
pes.
Wecanal
sopr
ovi
dev
alueswhi
l
edecl
ari
ngt
hev
ari
abl
esasgi
venbel
ow:
● i
nta=10,
b=20;
//decl
ari
ng2v
ari
abl
eofi
ntegert
ype
● f
loatf
=20.
8;
● charc='
A';
Rul
esf
ordef
ini
ngv
ari
abl
es
● Av
ari
abl
ecanhav
eal
phabet
s,di
git
s,andunder
scor
e.
● Av
ari
abl
enamecanst
artwi
tht
heal
phabet
,andunder
scor
eonl
y.I
tcan'
tst
art
wi
thadi
git
.
● Nowhi
tespacei
sal
l
owedwi
thi
nthev
ari
abl
ename.
● Av
ari
abl
enamemustnotbeanyr
eser
vedwor
dorkey
wor
d,e.
g.i
nt,
float
,et
c.
Val
idvar
iabl
enames:
● i
nta;
● i
nt_
ab;
● i
nta30;
I
nval
idvar
iabl
enames:
● i
nt2;
● i
ntab;
● i
ntl
ong;
Ty
pesofVar
iabl
esi
nC
Ther
ear
emanyt
ypesofv
ari
abl
esi
nc:
1.l
ocal
var
iabl
e
2.gl
obal
var
iabl
e
3.st
ati
cvar
iabl
e
4.aut
omat
icv
ari
abl
e
5.ex
ter
nal
var
iabl
e
Local
Var
iabl
e
Av
ari
abl
ethati
sdecl
aredi
nsi
det
hef
unct
ionorbl
ocki
scal
l
edal
ocal
var
iabl
e.
I
tmustbedecl
aredatt
hest
artoft
hebl
ock.
voi
dfunct
ion1(
){
i
ntx
=10;
//l
ocal
var
iabl
e
Youmusti
nit
ial
i
zet
hel
ocal
var
iabl
ebef
orei
tisused.
Gl
obal
Var
iabl
e
Avari
ablet
hatisdecl
aredout
sidet
hefuncti
onorblocki
scall
edaglobal
vari
abl
e.Anyf
unct
ion
canchangetheval
ueofthegl
obalvar
iabl
e.I
tisavai
labl
etoal
lthef
uncti
ons.
I
tmustbedecl
aredatt
hest
artoft
hebl
ock.
i
ntv
alue=20;
//gl
obal
var
iabl
e
v
oidf
unct
ion1(
){
i
ntx=10;
//l
ocal
var
iabl
e
St
ati
cVar
iabl
e
Av
ari
abl
ethati
sdecl
aredwi
tht
hest
ati
ckey
wor
discal
l
edst
ati
cvar
iabl
e.
I
tret
ainsi
tsv
aluebet
weenmul
ti
plef
unct
ioncal
l
s.
v
oidf
unct
ion1(
){
i
ntx=10;
//l
ocal
var
iabl
e
st
ati
cinty
=10;
//st
ati
cvar
iabl
e
x=x+1;
y
=y+1;
pr
int
f("
%d,
%d"
,x,
y);
}
I
fyoucal
lthi
sfunct
ionmanyt
imes,
thel
ocalvar
iabl
ewi
llpr
intt
hesameval
uef
oreach
f
unct
ioncal
l
,e.
g,11,
11,
11andsoon.Butt
hest
ati
cvar
iabl
ewi
llpr
intt
hei
ncr
ement
ed
val
uei
neachf
unct
ioncal
l
,e.
g.11,
12,
13andsoon.
Aut
omat
icVar
iabl
e
Al
lvar
iabl
esi
nCt
hatar
edecl
aredi
nsi
det
hebl
ockar
eaut
omat
icv
ari
abl
esbydef
aul
t.
Wecanex
pli
cit
lydecl
areanaut
omat
icv
ari
abl
eusi
ngt
heaut
okeywor
d.
voi
dmai
n()
{
i
ntx
=10;
//l
ocal
var
iabl
e(al
soaut
omat
ic)
aut
ointy
=20;
//aut
omat
icv
ari
abl
e
Ex
ter
nal
Var
iabl
e
Wecanshar
eav
ari
abl
einmul
ti
pleCsour
cef
il
esbyusi
nganex
ter
nalv
ari
abl
e.To
decl
areanex
ter
nal
var
iabl
e,y
ouneedt
ouseext
ernkeywor
d.
ext
erni
ntx
=10;
//ex
ter
nal
var
iabl
e(al
sogl
obal
)
pr
ogr
am1.
c
#i
ncl
ude"
myf
il
e.h"
#i
ncl
ude<st
dio.
h>
voi
dpr
int
Val
ue(
){
pr
int
f("
Global
var
iabl
e:%d"
,gl
obal
_var
iabl
e);
CI
dent
if
ier
s
Ci
dent
if
ier
srepr
esentt
henamei
ntheCpr
ogr
am,f
orex
ampl
e,v
ari
abl
es,f
unct
ions,
ar
ray
s,st
ruct
ures,uni
ons,l
abel
s,et
c.Ani
dent
if
iercanbecomposedofl
ett
erssuchas
upper
case,l
ower
casel
ett
ers,under
scor
e,di
git
s,butt
hest
art
ingl
ett
ershoul
dbeei
ther
anal
phabetoranunder
scor
e.I
fthei
dent
if
ieri
snotusedi
ntheex
ter
nall
i
nkage,
theni
t
i
scal
l
edasani
nter
nali
dent
if
ier
.Ift
hei
dent
if
ieri
susedi
ntheex
ter
nall
i
nkage,
theni
tis
cal
l
edasanex
ter
nal
ident
if
ier
.
Wecansayt
hatani
dent
if
ieri
sacol
l
ect
ionofal
phanumer
icchar
act
erst
hatbegi
ns
ei
therwi
thanal
phabet
icalchar
act
eroranunder
scor
e,whi
char
eusedt
orepr
esent
v
ari
ouspr
ogr
ammi
ngel
ement
ssuchasv
ari
abl
es,f
unct
ions,ar
ray
s,st
ruct
ures,uni
ons,
l
abel
s,et
c.Ther
ear
e52al
phabet
ical
char
act
ers(
upper
caseandl
ower
case)
,under
scor
e
char
act
er,andt
ennumer
icaldi
git
s(0-
9)t
hatr
epr
esentt
hei
dent
if
ier
s.Ther
ear
eat
otal
of63al
phanumer
icchar
act
erst
hatr
epr
esentt
hei
dent
if
ier
s.
Rul
esf
orconst
ruct
ingCi
dent
if
ier
s
● Thef
ir
stchar
act
erofani
dent
if
iershoul
dbeei
theranal
phabetoranunder
scor
e,
andt
heni
tcanbef
oll
owedbyanyoft
hechar
act
er,
digi
t,orunder
scor
e.
● I
tshoul
dnotbegi
nwi
thanynumer
ical
digi
t.
● I
nident
if
ier
s,bot
hupper
caseandl
ower
casel
ett
ersar
edi
sti
nct
.Ther
efor
e,we
cansayt
hati
dent
if
ier
sar
ecasesensi
ti
ve.
● Commasorbl
ankspacescannotbespeci
fi
edwi
thi
nani
dent
if
ier
.
● Key
wor
dscannotber
epr
esent
edasani
dent
if
ier
.
● Thel
engt
hoft
hei
dent
if
ier
sshoul
dnotbemor
ethan31char
act
ers.
● I
dent
if
ier
sshoul
dbewr
it
teni
nsuchawayt
hati
tismeani
ngf
ul,
shor
t,andeasyt
o
r
ead.
Exampl
eofval
idi
dent
if
ier
s
1.t
otal
,sum,
aver
age,
_m_
,sum_
1,et
c.
Exampl
eofi
nval
idi
dent
if
ier
s
1.2sum (
star
tswi
thanumer
ical
digi
t)
2.i
nt(
reser
vedwor
d)
3.char(
reser
vedwor
d)
4.m+n(
speci
alchar
act
er,
i.
e.,
'+'
)
Ty
pesofi
dent
if
ier
s
● I
nter
nal
ident
if
ier
● Ex
ter
nal
ident
if
ier
I
nter
nalI
dent
if
ier
I
fthei
dent
if
ieri
snotusedi
ntheex
ter
nall
i
nkage,t
heni
tisknownasani
nter
nal
i
dent
if
ier
.Thei
nter
nal
ident
if
ier
scanbel
ocal
var
iabl
es.
Ext
ernalI
dent
if
ier
I
fthei
dent
if
ieri
susedi
ntheex
ter
nall
i
nkage,t
heni
tisknownasanex
ter
nali
dent
if
ier
.
Theex
ter
nal
ident
if
ier
scanbef
unct
ionnames,
global
var
iabl
es.
Key
wor
dsi
nC
Akey
wor
disar
eser
vedwor
d.Youcannotusei
tasav
ari
abl
ename,
const
antname,
etc.
Ther
ear
eonl
y32r
eser
vedwor
ds(
key
wor
ds)i
ntheCl
anguage.
Al
i
stof32key
wor
dsi
nthecl
anguagei
sgi
venbel
ow:
aut
o br
eak case char const cont
inue def
aul
t do
doubl
e el
se enum ex
ter
n f
loat f
or got
o i
f
i
nt l
ong r
egi
ster r
etur
n shor
t si
gned si
zeof st
ati
c
st
ruct swi
tch t
ypedef uni
on unsi
gned v
oid v
olat
il
e whi
l
e
Di
ff
erencesbet
weenKey
wor
dandI
dent
if
ier
Key
wor
d I
dent
if
ier
Key
wor
disapr
edef
inedwor
d. Thei
dent
if
ieri
sauser
-def
inedwor
d
I
tmustbewr
it
teni
nal
ower
case I
tcanbewr
it
teni
nbot
hlower
caseand
l
ett
er. upper
casel
ett
ers.
I
tsmeani
ngi
spr
e-def
inedi
ntheC I
ts meani
ng i
s not def
ined i
nthe c
compi
l
er. compi
l
er.
I
tisacombi
nat
ionofal
phabet
ical I
tis a combi
nat
ion of al
phanumer
ic
char
act
ers. char
act
ers.
I
t does not cont
ain t
he I
tcancont
aint
heunder
scor
echar
act
er.
under
scor
echar
act
er.
Dat
aTy
pesi
nC
Adat
aty
pespeci
fi
est
het
ypeofdat
athatav
ari
abl
ecanst
oresuchasi
nteger
,fl
oat
ing,
char
act
er,
etc.
Ther
ear
ethef
oll
owi
ngdat
aty
pesi
nCl
anguage.
Ty
pes Dat
aTy
pes
Basi
cDat
aTy
pe i
nt,
char
,fl
oat
,doubl
e
Der
ivedDat
aTy
pe ar
ray
,poi
nter
,st
ruct
ure,
uni
on
Enumer
ati
onDat
aTy
pe enum
Voi
dDat
aTy
pe v
oid
Basi
cDat
aTy
pes
Thebasi
cdat
aty
pesar
eint
eger
-basedandf
loat
ing-
poi
ntbased.Cl
anguagesuppor
ts
bot
hsi
gnedandunsi
gnedl
i
ter
als.
Thememor
ysi
zeoft
hebasi
cdat
aty
pesmaychangeaccor
ding t
o 32 or64-
bit
oper
ati
ngsy
stem.
I
tssi
zei
sgi
venaccor
dingt
o32-
bitar
chi
tect
ure.
Dat
aTy
pes Memor
ySi
ze Range
char 1by
te −128t
o127
si
gnedchar 1by
te −128t
o127
unsi
gnedchar 1by
te 0t
o255
shor
t 2by
te −32,
768t
o32,
767
si
gnedshor
t 2by
te −32,
768t
o32,
767
unsi
gnedshor
t 2by
te 0t
o65,
535
i
nt 2by
te −32,
768t
o32,
767
si
gnedi
nt 2by
te −32,
768t
o32,
767
unsi
gnedi
nt 2by
te 0t
o65,
535
shor
tint 2by
te −32,
768t
o32,
767
si
gnedshor
tint 2by
te −32,
768t
o32,
767
unsi
gnedshor
tint 2by
te 0t
o65,
535
l
ongi
nt 4by
te -
2,147,
483,
648t
o2,
147,
483,
647
si
gnedl
ongi
nt 4by
te -
2,147,
483,
648t
o2,
147,
483,
647
unsi
gnedl
ongi
nt 4by
te 0t
o4,
294,
967,
295
f
loat 4by
te 1E-
37t
o1E+37al
ongwi
thsi
xdi
git
s
oft
hepr
eci
sionsher
e
doubl
e 8by
te 1E-
37t
o1E+37al
ongwi
thsi
xdi
git
s
oft
hepr
eci
sionsher
e
l
ongdoubl
e 10by
te 1E-
37t
o1E+37al
ongwi
thsi
xdi
git
sof
t
hepr
eci
sionsher
e
i
nt
I
nteger
sar
ewhol
enumber
sthatcanhav
ebot
hzer
o,posi
ti
veandnegat
ive
v
aluesbutnodeci
mal
val
ues.Forexampl
e,0,
-5,
10
Wecanusei
ntf
ordecl
ari
ngani
ntegerv
ari
abl
e.
i
nti
d;
Her
e,di
i sav
ari
abl
eoft
ypei
nteger
.
Youcandecl
aremul
ti
plev
ari
abl
esatoncei
nCpr
ogr
ammi
ng.Forexampl
e,
i
nti
d,age;
Thesi
zeofi
nti
susual
l
y4by
tes(
32bi
ts)
.And,
i ake232di
tcant sti
nctst
ates
f
rom -
2147483648t
o2147483647.
f
loatanddoubl
e
f
loatanddoubl
ear
eusedt
ohol
dreal
number
s.
f
loatsal
ary
;
doubl
epr
ice;
I
nC,
float
ing-
poi
ntnumber
scanal
sober
epr
esent
edi
nexponent
ial
.For
exampl
e,
f
loatnor
mal
i
zat
ionFact
or=22.
442e2;
What
'
sthedi
ff
erencebet
weenf
loatanddoubl
e?
Thesi
zeoff
loat(
singl
epr
eci
sionf
loatdat
aty
pe)i
s4by
tes.Andt
hesi
zeof
e(
doubl doubl
epr
eci
si
onf
loatdat
aty
pe)i
s8by
tes.
char
Key
wor
dchari
susedf
ordecl
ari
ngchar
act
ert
ypev
ari
abl
es.Forexampl
e,
chart
est='
h'
;
Thesi
zeoft
hechar
act
erv
ari
abl
eis1by
te.
v
oid
v
oidi
sani
ncompl
etet
ype.I
tmeans"
not
hing"or"
not
ype"
.Youcant
hinkof
v
oidasabsent
.
Forexampl
e,i
faf
unct
ioni
snotr
etur
ningany
thi
ng,
itsr
etur
nty
peshoul
dbe
v
oid.
Not
ethat
,youcannotcr
eat
evar
iabl
esofvoi
dty
pe.
shor
tandl
ong
I
fyouneedt
ouseal
argenumber
,youcanuseat
ypespeci
fi
erl
ong.Her
e's
how:
l
onga;
l
ongl
ongb;
l
ongdoubl
ec;
Her
evar
iabl
esaandbcanst
orei
ntegerv
alues.And,
ccanst
oreaf
loat
ing-
poi
ntnumber
.
I
fyouar
esur
e,onl
yasmal
li
nteger(
[−32,
767, 767]r
+32, ange)wi
l
lbeused,
you
canuseshor
t.
shor
td;
si
gnedandunsi
gned
I
nC,
signedandunsi
gnedar
ety
pemodi
fi
ers.Youcanal
tert
hedat
ast
orageofa
dat
aty
pebyusi
ngt
hem:
gned-
● si al
l
owsf
orst
orageofbot
hposi
ti
veandnegat
ivenumber
s
gned-
● unsi al
l
owsf
orst
orageofonl
yposi
ti
venumber
s
Forexampl
e,
/
/val
i
dcodes
unsi
gnedi
ntx=35;
i
nty=-
35;/
/si
gnedi
nt
i
ntz=36;/
/si
gnedi
nt
/
/inv
ali
dcode:
unsi
gnedi
ntcannothol
dnegat
ivei
nteger
s
unsi
gnedi
ntnum =-
35;
Her
e,t
hev ar
iabl
esxandnum canholdonl
yzer
oandposi
ti
vev
aluesbecause
wehaveusedtheunsi
gnedmodif
ier
.