SlideShare a Scribd company logo
Introduction ttoo PPrrooggrraammmmiinngg 
LLeeccttuurree 1100
TTooddaayy''ss LLeeccttuurree IInncclluuddeess 
 HHeeaaddeerr FFiilleess 
 SSccooppee ooff VVaarriiaabblleess 
 FFuunnccttiioonnss 
– CCaallll bbyy vvaalluuee 
– CCaallll bbyy rreeffeerreennccee
HHeeaaddeerr FFiilleess 
##iinncclluuddee <<iioossttrreeaamm..hh>>
PPrroottoottyyppee 
Return value Assignment List 
with data type 
iinntt ffuunnccttiioonnNNaammee ( iinntt ,, iinntt ));;
UUssiinngg HHeeaaddeerr FFiilleess 
ddoouubbllee ppii == 33..11441155992266;; 
 IItt iiss bbeetttteerr ttoo ddeeffiinnee tthhiiss vvaalluuee iinn aa hheeaaddeerr ffiillee 
 TThheenn ssiimmppllyy bbyy iinncclluuddiinngg tthhee hheeaaddeerr ffiillee iinn tthhee 
pprrooggrraamm tthhiiss vvaalluuee iiss ddeeffiinneedd aanndd iitt hhaass aa 
mmeeaanniinnggffuull nnaammee
#define 
 ##ddeeffiinnee ppii 33..11441155992266 
 NNaammee ccaann bbee uusseedd iinnssiiddee aa pprrooggrraamm 
eexxaaccttllyy lliikkee aa vvaarriiaabbllee 
 IItt ccaannnnoott bbee uusseedd aass aa vvaarriiaabbllee 
CCiirrcclleeAArreeaa == ppii ** rraaddiiuuss ** rraaddiiuuss 
CCiirrccuummffeerreennccee == 22 ** ppii ** rraaddiiuuss
SSccooppee ooff IIddeennttiiffiieerrss 
 Identifier is aannyy nnaammee uusseerr ccrreeaatteess iinn 
hhiiss//hheerr pprrooggrraamm 
 FFuunnccttiioonnss aarree aallssoo iiddeennttiiffiieerrss 
 LLaabbeellss aarree aallssoo iiddeennttiiffiieerrss
SSccooppee ooff IIddeennttiiffiieerrss 
 SSccooppee mmeeaannss vviissiibbiilliittyy 
 AA vvaarriiaabbllee ddeeccllaarreedd iinnssiiddee aa bblloocckk hhaass 
vviissiibbiilliittyy wwiitthhiinn tthhaatt bblloocckk oonnllyy 
 VVaarriiaabblleess ddeeffiinneedd wwiitthhiinn tthhee ffuunnccttiioonn 
hhaass aa ssccooppee tthhaatt iiss ffuunnccttiioonn wwiiddee
EExxaammppllee 
vvooiidd ffuunnccttiioonnNNaammee (( )) 
{{ 
{{ 
iinntt ii ;; 
}} 
…….... 
}}
IIddeennttiiffiieerrss IImmppoorrttaanntt PPooiinnttss 
 DDoo nnoott ccrreeaattee vvaarriiaabblleess wwiitthh ssaammee 
nnaammee iinnssiiddee bblloocckkss,, iinnssiiddee ffuunnccttiioonnss 
oorr iinnssiiddee bbiiggggeerr bblloocckkss 
 TTrryy ttoo uussee sseeppaarraattee vvaarriiaabbllee nnaammeess 
ttoo aavvooiidd ccoonnffuussiioonn 
 RReeuussee ooff vvaarriiaabblleess iiss vvaalliidd
FFiillee SSccooppee 
## iinncclluuddee << iioossttrreeaamm..hh >> 
iinntt ii ;; 
Global variable
GGlloobbaall VVaarriiaabbllee 
 CCaann bbee uusseedd aannyywwhheerree iinn pprrooggrraamm 
 CCaann ccaauussee llooggiiccaall pprroobblleemmss iiff ssaammee vvaarriiaabbllee 
nnaammee iiss uusseedd iinn llooccaall vvaarriiaabbllee ddeeccllaarraattiioonnss 
FFoorr ggoooodd pprrooggrraammmmiinngg 
 TTrryy ttoo mmiinniimmiizzee tthhee uussee ooff gglloobbaall vvaarriiaabblleess 
 TTrryy ttoo uussee llooccaall vvaarriiaabblleess aass ffaarr aass ppoossssiibbllee
VViissiibbiilliittyy ooff IIddeennttiiffiieerrss 
 GGlloobbaall SSccooppee 
AAnnyytthhiinngg iiddeennttiiffiieedd oorr ddeeccllaarreedd oouuttssiiddee ooff 
aannyy ffuunnccttiioonn iiss vviissiibbllee ttoo aallll ffuunnccttiioonnss iinn tthhaatt 
ffiillee 
 FFuunnccttiioonn lleevveell ssccooppee 
DDeeccllaarriinngg vvaarriiaabblleess iinnssiiddee aa ffuunnccttiioonn ccaann bbee 
uusseedd iinn tthhee wwhhoollee ffuunnccttiioonn 
 BBlloocckk lleevveell ssccooppee 
VVaarriiaabblleess oorr iinntteeggeerrss ddeeccllaarreedd iinnssiiddee bblloocckk 
aarree uusseedd iinnssiiddee bblloocckk
EExxaammppllee: BBlloocckk SSccooppee 
ffoorr (( iinntt ii == 00 ;; ii << 1100 ;; ii++++ )) 
 IItt iiss bblloocckk lleevveell ssccooppee ddeeccllaarreedd iinn ffoorr 
lloooopp 
 WWhheenn ffoorr iiss ffiinniisshheedd ““ ii ”” nnoo lloonnggeerr 
eexxiissttss
EExxaammppllee: GGlloobbaall SSccooppee 
##iinncclluuddee << iioossttrreeaamm..hh >> 
iinntt ii ;; 
vvooiidd ff (( vvooiidd )) ;; 
mmaaiinn (( )) 
{{ 
ii == 1100 ;; 
ccoouutt<<<< ““ wwiitthhiinn mmaaiinn ii == ““ <<<< ii ;; 
ff (( )) ;; 
}}
EExxaammppllee: GGlloobbaall SSccooppee 
vvooiidd ff (( vvooiidd )) 
{{ 
ccoouutt<<<< ““ IInnssiiddee ffuunnccttiioonn ff ,, ii ==““ <<<< ii ;; 
ii == 2200 ;; 
}}
EExxaammppllee:: CCaallll bbyy VVaalluuee 
##iinncclluuddee <<iioossttrreeaamm..hh >> 
iinntt ff (( iinntt )) ;; 
mmaaiinn (( )) 
{{ 
iinntt ii == 1100 ;; 
ccoouutt <<<< ““IInn mmaaiinn ii == "" <<<< ii ;; 
ff (( ii )) ;; 
ccoouutt <<<< "" BBaacckk iinn mmaaiinn,, ii == "" <<<< ii ;; 
s 
}}
iinntt ff (( iinntt ii )) 
{{ 
ccoouutt <<<< ""IInn ffuunnccttiioonn ff ,, ii == "" <<<< ii ;; 
ii **== 22 ;; 
ccoouutt <<<< ""IInn ffuunnccttiioonn ff ,, ii iiss nnooww == ““ <<<< ii ;; 
rreettuurrnn ii ;; 
}} 
EExxaammppllee:: CCaallll bbyy 
VVaalluuee
double square (( ddoouubbllee xx )) 
{{ 
rreettuurrnn xx ** xx ;; 
}} 
mmaaiinn (( )) 
{{ 
ddoouubbllee nnuummbbeerr == 112233..445566 ;; 
ccoouutt <<<< ““ TThhee ssqquuaarree ooff ““ <<<< nnuummbbeerr <<<< ““ iiss ““<<<< ssqquuaarree (( nnuummbbeerr )) ;; 
ccoouutt <<<< ““ TThhee ccuurrrreenntt vvaalluuee ooff ““ <<<< nnuummbbeerr <<<< ““iiss ““ <<<< nnuummbbeerr ;; 
}} 
EExxaammppllee :: SSqquuaarree ooff aa 
NNuummbbeerr
MMaatthh..hh 
##iinncclluuddee << mmaatthh..hh >> 
ddoouubbllee ssqqrrtt (( ddoouubbllee ));; 
lloogg1100 ,, ppooww (( xxyy )) ,, ssiinn ,, ccooss ,, ttaann ……
CCaallll bbyy RReeffeerreennccee 
 AA ffuunnccttiioonn iinn wwhhiicchh oorriiggiinnaall vvaalluuee ooff tthhee 
vvaarriiaabbllee iiss cchhaannggeedd 
 TToo ccaallll bbyy rreeffeerreennccee wwee ccaannnnoott ppaassss 
vvaalluuee,, wwee hhaavvee ttoo ppaassss mmeemmoorryy aaddddrreessss 
ooff vvaarriiaabbllee 
 ““&&”” iiss uusseedd ttoo ttaakkee tthhee aaddddrreessss ooff aa 
vvaarriiaabbllee
EExxaammppllee:: CCaallll bbyy 
RReeffeerreennccee 
mmaaiinn (( )) 
{{ 
ddoouubbllee xx == 112233..445566 ;; 
ssqquuaarree (( &&xx )) ;; 
}} 
VVaalluuee ooff ‘‘xx’’ iiss nnoott ppaasssseedd ,, bbuutt tthhee 
mmeemmoorryy aaddddrreessss ooff ‘‘xx’’ iiss ppaasssseedd
EExxaammppllee:: CCaallll bbyy 
RReeffeerreennccee 
x is a pointer to a variable double 
ssqquuaarree (( ddoouubbllee **xx )) 
{{ 
**xx == **xx ** **xx ;; 
}}
PPooiinntteerrss 
 Pointers aarree uusseedd ttoo ppaassss aaddddrreessss ooff 
vvaarriiaabbllee ffoorr rreeffeerreennccee 
 WWee uussee ““ &&xx ”” ttoo sseenndd tthhee aaddddrreessss ooff ““ 
xx ““ 
 TToo rreecceeiivvee tthhee aaddddrreessss wwee uussee ““ **xx ”” 
((wwhhaatteevveerr ““ xx ”” ppooiinnttss ttoo))
RReeccuurrssiivvee 
FFuunnccttiioonnss 
 Special function wwhhiicchh ccaann ccaallll iittsseellff 
xx1100 == xx ** xx99 
xx99 == xx ** xx88 
xx88 == xx ** xx77 
…… …… 
xxnn == xx ** xxnn--11
RReeccuurrssiivvee FFuunnccttiioonnss:: 
FFaaccttoorriiaall 
nn!! == nn ** ((nn--11)) ** ((nn--22)) ………….... 33 ** 22 ** 11 
55!! == 55 ** 44 ** 33 ** 22 ** 11 
44!! == 44 ** 33 ** 22 ** 11 
55!! == 55 ** 44!! 
00!! == 11
RReeccuurrssiivvee FFuunnccttiioonnss:: FFaaccttoorriiaall 
lloonngg ffaaccttoorriiaall (( lloonngg nn )) 
{{ 
iiff ((nn ==== 11 )) 
rreettuurrnn (( nn )) ;; 
eellssee 
rreettuurrnn (( nn ** ffaaccttoorriiaall ((nn--11)) )) ;; 
}}
EExxeerrcciissee 
TTrryy ttoo wwrriittee pprrooggrraamm ffoorr 
 FFiibboonnaaccccii sseerriieess 
 FFiinndd ‘‘ppoowweerr ooff nnuummbbeerr’’ uussiinngg rreeccuurrssiivvee 
tteecchhnniiqquuee
EExxaammppllee 
TThhee FFiibboonnaaccccii SSeerriieess 
 SSeett ooff rreeccuurrssiivvee ccaallllss ttoo ffuunnccttiioonn 
ffiibboonnaaccccii 
f( 3 ) 
return + 
f( 2 ) f( 1 ) 
return + 
f( 1 ) f( 0 ) return 1 
return 1 return 0
MMaannaaggeemmeenntt IIssssuueess ooff 
CCoommppuutteerr 
TThheerree aarree ttwwoo iissssuueess iinnssiiddee aa ccoommppuutteerr 
 MMeemmoorryy oovveerrhheeaadd 
 SSttaacckk oovveerrhheeaadd
PPrrooggrraammmmiinngg OOppttiioonnss 
 EElleeggaanntt ccooddee 
wwhheerree pprriiccee iiss nnoott ttoooo hhiigghh 
 EEffffiicciieenntt ccooddee 
wwhheerree pprriiccee iiss ttoooo hhiigghh
WWhhaatt hhaavvee wwee DDoonnee TTooddaayy …… 
 HHeeaaddeerr FFiilleess 
– NNiiccee mmeecchhaanniissmm ooff ppuuttttiinngg aallll pprroottoottyyppeess 
aanndd ddeeffiinniittiioonnss ooff gglloobbaall ccoonnssttaannttss eettcc.. 
 SSccooppee ooff vvaarriiaabblleess 
 FFuunnccttiioonnss 
– CCaallll bbyy vvaalluuee 
– CCaallll bbyy rreeffeerreennccee 
 RReeccuurrssiioonn

More Related Content

What's hot

cardiac arrhythmias
cardiac arrhythmiascardiac arrhythmias
cardiac arrhythmias
majid shojaee
 
Comandos para diseño de página Web
Comandos para diseño de página WebComandos para diseño de página Web
Comandos para diseño de página Web
Armando Bond
 
Edit data base menggunakan web
Edit data base menggunakan webEdit data base menggunakan web
Edit data base menggunakan web
haviedz miftah
 
Upper tibial valgus osteotomy using a dynamic external fixator
Upper tibial valgus osteotomy using a dynamic external fixatorUpper tibial valgus osteotomy using a dynamic external fixator
Upper tibial valgus osteotomy using a dynamic external fixator
Alexander Bardis
 
The anatomy of a dollar bill
The anatomy of a dollar billThe anatomy of a dollar bill
The anatomy of a dollar billSeadin Xhaferi
 
CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 12
CS201- Introduction to Programming- Lecture 12CS201- Introduction to Programming- Lecture 12
CS201- Introduction to Programming- Lecture 12
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03
Bilal Ahmed
 
Ancient israel
Ancient israelAncient israel
Ancient israel
Jordon Vechsler
 
Le Black's Law Dictionary, monument de la lexicographie juridique - ATA 2010
Le Black's Law Dictionary, monument de la lexicographie juridique - ATA 2010Le Black's Law Dictionary, monument de la lexicographie juridique - ATA 2010
Le Black's Law Dictionary, monument de la lexicographie juridique - ATA 2010
Frédéric Houbert
 
Acceleration and force 2010
Acceleration and force 2010Acceleration and force 2010
Acceleration and force 2010sbarkanic
 
4th grade, lesson plan
4th grade, lesson plan4th grade, lesson plan
4th grade, lesson plan
cpapadak
 
Symmetry and group theory
Symmetry and group theorySymmetry and group theory
Symmetry and group theory
Rawat DA Greatt
 
Sexually transmitted infections
Sexually transmitted infectionsSexually transmitted infections
Sexually transmitted infections
Lisa Johnson-Bowers
 
CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24
Bilal Ahmed
 
Estados hipertensivos del embarazo
Estados hipertensivos del embarazoEstados hipertensivos del embarazo
Estados hipertensivos del embarazo
87880404
 
Resumen termoquimica1
Resumen termoquimica1Resumen termoquimica1
Resumen termoquimica1
Francisco Rodríguez Pulido
 
Design of the South Doña Ana Dam
Design of the South Doña Ana DamDesign of the South Doña Ana Dam
Design of the South Doña Ana Dam
Desh Sonyok
 
Creative commons and the ethical use of images in language instruction shelton
Creative commons and the ethical use of images in language instruction sheltonCreative commons and the ethical use of images in language instruction shelton
Creative commons and the ethical use of images in language instruction sheltonDonna Shelton
 

What's hot (20)

cardiac arrhythmias
cardiac arrhythmiascardiac arrhythmias
cardiac arrhythmias
 
Comandos para diseño de página Web
Comandos para diseño de página WebComandos para diseño de página Web
Comandos para diseño de página Web
 
Edit data base menggunakan web
Edit data base menggunakan webEdit data base menggunakan web
Edit data base menggunakan web
 
Upper tibial valgus osteotomy using a dynamic external fixator
Upper tibial valgus osteotomy using a dynamic external fixatorUpper tibial valgus osteotomy using a dynamic external fixator
Upper tibial valgus osteotomy using a dynamic external fixator
 
The anatomy of a dollar bill
The anatomy of a dollar billThe anatomy of a dollar bill
The anatomy of a dollar bill
 
CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30
 
CS201- Introduction to Programming- Lecture 12
CS201- Introduction to Programming- Lecture 12CS201- Introduction to Programming- Lecture 12
CS201- Introduction to Programming- Lecture 12
 
CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03
 
Ancient israel
Ancient israelAncient israel
Ancient israel
 
Le Black's Law Dictionary, monument de la lexicographie juridique - ATA 2010
Le Black's Law Dictionary, monument de la lexicographie juridique - ATA 2010Le Black's Law Dictionary, monument de la lexicographie juridique - ATA 2010
Le Black's Law Dictionary, monument de la lexicographie juridique - ATA 2010
 
Acceleration and force 2010
Acceleration and force 2010Acceleration and force 2010
Acceleration and force 2010
 
4th grade, lesson plan
4th grade, lesson plan4th grade, lesson plan
4th grade, lesson plan
 
Symmetry and group theory
Symmetry and group theorySymmetry and group theory
Symmetry and group theory
 
Sexually transmitted infections
Sexually transmitted infectionsSexually transmitted infections
Sexually transmitted infections
 
CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24
 
Tiro parabólico
Tiro parabólicoTiro parabólico
Tiro parabólico
 
Estados hipertensivos del embarazo
Estados hipertensivos del embarazoEstados hipertensivos del embarazo
Estados hipertensivos del embarazo
 
Resumen termoquimica1
Resumen termoquimica1Resumen termoquimica1
Resumen termoquimica1
 
Design of the South Doña Ana Dam
Design of the South Doña Ana DamDesign of the South Doña Ana Dam
Design of the South Doña Ana Dam
 
Creative commons and the ethical use of images in language instruction shelton
Creative commons and the ethical use of images in language instruction sheltonCreative commons and the ethical use of images in language instruction shelton
Creative commons and the ethical use of images in language instruction shelton
 

Viewers also liked

CS201- Introduction to Programming- Lecture 34
CS201- Introduction to Programming- Lecture 34CS201- Introduction to Programming- Lecture 34
CS201- Introduction to Programming- Lecture 34
Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 43
CS101- Introduction to Computing- Lecture 43CS101- Introduction to Computing- Lecture 43
CS101- Introduction to Computing- Lecture 43
Bilal Ahmed
 
MTH101 - Calculus and Analytical Geometry- Lecture 44
MTH101 - Calculus and Analytical Geometry- Lecture 44MTH101 - Calculus and Analytical Geometry- Lecture 44
MTH101 - Calculus and Analytical Geometry- Lecture 44
Bilal Ahmed
 
ENG101- English Comprehension- Lecture 35
ENG101- English Comprehension- Lecture 35ENG101- English Comprehension- Lecture 35
ENG101- English Comprehension- Lecture 35
Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32
Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 16CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 16
Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19
Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 38
MGT101 - Financial Accounting- Lecture 38MGT101 - Financial Accounting- Lecture 38
MGT101 - Financial Accounting- Lecture 38
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39
Bilal Ahmed
 
ENG101- English Comprehension- Lecture 43
ENG101- English Comprehension- Lecture 43ENG101- English Comprehension- Lecture 43
ENG101- English Comprehension- Lecture 43
Bilal Ahmed
 
ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 08
CS201- Introduction to Programming- Lecture 08CS201- Introduction to Programming- Lecture 08
CS201- Introduction to Programming- Lecture 08
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43
Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40
Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44
Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23
Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 30
MGT101 - Financial Accounting- Lecture 30MGT101 - Financial Accounting- Lecture 30
MGT101 - Financial Accounting- Lecture 30
Bilal Ahmed
 

Viewers also liked (20)

CS201- Introduction to Programming- Lecture 34
CS201- Introduction to Programming- Lecture 34CS201- Introduction to Programming- Lecture 34
CS201- Introduction to Programming- Lecture 34
 
CS101- Introduction to Computing- Lecture 43
CS101- Introduction to Computing- Lecture 43CS101- Introduction to Computing- Lecture 43
CS101- Introduction to Computing- Lecture 43
 
MTH101 - Calculus and Analytical Geometry- Lecture 44
MTH101 - Calculus and Analytical Geometry- Lecture 44MTH101 - Calculus and Analytical Geometry- Lecture 44
MTH101 - Calculus and Analytical Geometry- Lecture 44
 
ENG101- English Comprehension- Lecture 35
ENG101- English Comprehension- Lecture 35ENG101- English Comprehension- Lecture 35
ENG101- English Comprehension- Lecture 35
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32
 
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29
 
CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06
 
CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 16CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 16
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35
 
CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19
 
MGT101 - Financial Accounting- Lecture 38
MGT101 - Financial Accounting- Lecture 38MGT101 - Financial Accounting- Lecture 38
MGT101 - Financial Accounting- Lecture 38
 
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39
 
ENG101- English Comprehension- Lecture 43
ENG101- English Comprehension- Lecture 43ENG101- English Comprehension- Lecture 43
ENG101- English Comprehension- Lecture 43
 
ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42
 
CS201- Introduction to Programming- Lecture 08
CS201- Introduction to Programming- Lecture 08CS201- Introduction to Programming- Lecture 08
CS201- Introduction to Programming- Lecture 08
 
CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43
 
MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40
 
CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44
 
CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23
 
MGT101 - Financial Accounting- Lecture 30
MGT101 - Financial Accounting- Lecture 30MGT101 - Financial Accounting- Lecture 30
MGT101 - Financial Accounting- Lecture 30
 

Similar to CS201- Introduction to Programming- Lecture 10

21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii
maznabili
 
Business plan presentation_format
Business plan presentation_formatBusiness plan presentation_format
Business plan presentation_format
bindur87
 
Spinal injuries
Spinal injuriesSpinal injuries
Spinal injuries
Alexander Bardis
 
18 Hash tables and sets
18 Hash tables and sets18 Hash tables and sets
18 Hash tables and sets
maznabili
 
Training methods
Training methodsTraining methods
Training methods
begraj SIWAL
 
19 Algorithms and complexity
19 Algorithms and complexity19 Algorithms and complexity
19 Algorithms and complexity
maznabili
 
solar activity and climate
solar activity and climatesolar activity and climate
solar activity and climate
Kees De Jager
 
13089861
1308986113089861
13089861
Isaias Castro
 
Solving linear equations (chapter 2)
Solving linear equations (chapter 2)Solving linear equations (chapter 2)
Solving linear equations (chapter 2)
Raza Zaidi
 
Justins turlip soil moisture REUcon
Justins turlip soil moisture REUconJustins turlip soil moisture REUcon
Justins turlip soil moisture REUcon
melnhe
 
Source control system
Source control systemSource control system
Source control system
DotNetMarche
 
06.introduction to middle third fractures
06.introduction to  middle third fractures  06.introduction to  middle third fractures
06.introduction to middle third fractures vasanramkumar
 
V wd soff 09-11-14
V wd soff 09-11-14V wd soff 09-11-14
V wd soff 09-11-14derosaMSKCC
 
CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38
Bilal Ahmed
 
Building types lecture
Building types lectureBuilding types lecture
Building types lecture
ANURUDDHKUMAR
 
Dielectrics lect28
Dielectrics lect28Dielectrics lect28
Dielectrics lect28Joao Tan
 
Securing PHP Applications
Securing PHP ApplicationsSecuring PHP Applications
Securing PHP Applications
Reggie Niccolo Santos
 
Call Centre Training Package
Call Centre Training PackageCall Centre Training Package
Call Centre Training PackageStephen J Landry
 

Similar to CS201- Introduction to Programming- Lecture 10 (20)

21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii
 
Business plan presentation_format
Business plan presentation_formatBusiness plan presentation_format
Business plan presentation_format
 
Spinal injuries
Spinal injuriesSpinal injuries
Spinal injuries
 
18 Hash tables and sets
18 Hash tables and sets18 Hash tables and sets
18 Hash tables and sets
 
Training methods
Training methodsTraining methods
Training methods
 
19 Algorithms and complexity
19 Algorithms and complexity19 Algorithms and complexity
19 Algorithms and complexity
 
solar activity and climate
solar activity and climatesolar activity and climate
solar activity and climate
 
13089861
1308986113089861
13089861
 
Solving linear equations (chapter 2)
Solving linear equations (chapter 2)Solving linear equations (chapter 2)
Solving linear equations (chapter 2)
 
Justins turlip soil moisture REUcon
Justins turlip soil moisture REUconJustins turlip soil moisture REUcon
Justins turlip soil moisture REUcon
 
Source control system
Source control systemSource control system
Source control system
 
06.introduction to middle third fractures
06.introduction to  middle third fractures  06.introduction to  middle third fractures
06.introduction to middle third fractures
 
V wd soff 09-11-14
V wd soff 09-11-14V wd soff 09-11-14
V wd soff 09-11-14
 
Corporation
CorporationCorporation
Corporation
 
CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36
 
CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38
 
Building types lecture
Building types lectureBuilding types lecture
Building types lecture
 
Dielectrics lect28
Dielectrics lect28Dielectrics lect28
Dielectrics lect28
 
Securing PHP Applications
Securing PHP ApplicationsSecuring PHP Applications
Securing PHP Applications
 
Call Centre Training Package
Call Centre Training PackageCall Centre Training Package
Call Centre Training Package
 

More from Bilal Ahmed

CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 29CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 29
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 20
CS201- Introduction to Programming- Lecture 20CS201- Introduction to Programming- Lecture 20
CS201- Introduction to Programming- Lecture 20
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18
Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17
Bilal Ahmed
 

More from Bilal Ahmed (20)

CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45
 
CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44
 
CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42
 
CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41
 
CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37
 
CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35
 
CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33
 
CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32
 
CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31
 
CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 29CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 29
 
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28
 
CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27
 
CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26
 
CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25
 
CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23
 
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22
 
CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21
 
CS201- Introduction to Programming- Lecture 20
CS201- Introduction to Programming- Lecture 20CS201- Introduction to Programming- Lecture 20
CS201- Introduction to Programming- Lecture 20
 
CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18
 
CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17
 

CS201- Introduction to Programming- Lecture 10

  • 2. TTooddaayy''ss LLeeccttuurree IInncclluuddeess  HHeeaaddeerr FFiilleess  SSccooppee ooff VVaarriiaabblleess  FFuunnccttiioonnss – CCaallll bbyy vvaalluuee – CCaallll bbyy rreeffeerreennccee
  • 3. HHeeaaddeerr FFiilleess ##iinncclluuddee <<iioossttrreeaamm..hh>>
  • 4. PPrroottoottyyppee Return value Assignment List with data type iinntt ffuunnccttiioonnNNaammee ( iinntt ,, iinntt ));;
  • 5. UUssiinngg HHeeaaddeerr FFiilleess ddoouubbllee ppii == 33..11441155992266;;  IItt iiss bbeetttteerr ttoo ddeeffiinnee tthhiiss vvaalluuee iinn aa hheeaaddeerr ffiillee  TThheenn ssiimmppllyy bbyy iinncclluuddiinngg tthhee hheeaaddeerr ffiillee iinn tthhee pprrooggrraamm tthhiiss vvaalluuee iiss ddeeffiinneedd aanndd iitt hhaass aa mmeeaanniinnggffuull nnaammee
  • 6. #define  ##ddeeffiinnee ppii 33..11441155992266  NNaammee ccaann bbee uusseedd iinnssiiddee aa pprrooggrraamm eexxaaccttllyy lliikkee aa vvaarriiaabbllee  IItt ccaannnnoott bbee uusseedd aass aa vvaarriiaabbllee CCiirrcclleeAArreeaa == ppii ** rraaddiiuuss ** rraaddiiuuss CCiirrccuummffeerreennccee == 22 ** ppii ** rraaddiiuuss
  • 7. SSccooppee ooff IIddeennttiiffiieerrss  Identifier is aannyy nnaammee uusseerr ccrreeaatteess iinn hhiiss//hheerr pprrooggrraamm  FFuunnccttiioonnss aarree aallssoo iiddeennttiiffiieerrss  LLaabbeellss aarree aallssoo iiddeennttiiffiieerrss
  • 8. SSccooppee ooff IIddeennttiiffiieerrss  SSccooppee mmeeaannss vviissiibbiilliittyy  AA vvaarriiaabbllee ddeeccllaarreedd iinnssiiddee aa bblloocckk hhaass vviissiibbiilliittyy wwiitthhiinn tthhaatt bblloocckk oonnllyy  VVaarriiaabblleess ddeeffiinneedd wwiitthhiinn tthhee ffuunnccttiioonn hhaass aa ssccooppee tthhaatt iiss ffuunnccttiioonn wwiiddee
  • 9. EExxaammppllee vvooiidd ffuunnccttiioonnNNaammee (( )) {{ {{ iinntt ii ;; }} …….... }}
  • 10. IIddeennttiiffiieerrss IImmppoorrttaanntt PPooiinnttss  DDoo nnoott ccrreeaattee vvaarriiaabblleess wwiitthh ssaammee nnaammee iinnssiiddee bblloocckkss,, iinnssiiddee ffuunnccttiioonnss oorr iinnssiiddee bbiiggggeerr bblloocckkss  TTrryy ttoo uussee sseeppaarraattee vvaarriiaabbllee nnaammeess ttoo aavvooiidd ccoonnffuussiioonn  RReeuussee ooff vvaarriiaabblleess iiss vvaalliidd
  • 11. FFiillee SSccooppee ## iinncclluuddee << iioossttrreeaamm..hh >> iinntt ii ;; Global variable
  • 12. GGlloobbaall VVaarriiaabbllee  CCaann bbee uusseedd aannyywwhheerree iinn pprrooggrraamm  CCaann ccaauussee llooggiiccaall pprroobblleemmss iiff ssaammee vvaarriiaabbllee nnaammee iiss uusseedd iinn llooccaall vvaarriiaabbllee ddeeccllaarraattiioonnss FFoorr ggoooodd pprrooggrraammmmiinngg  TTrryy ttoo mmiinniimmiizzee tthhee uussee ooff gglloobbaall vvaarriiaabblleess  TTrryy ttoo uussee llooccaall vvaarriiaabblleess aass ffaarr aass ppoossssiibbllee
  • 13. VViissiibbiilliittyy ooff IIddeennttiiffiieerrss  GGlloobbaall SSccooppee AAnnyytthhiinngg iiddeennttiiffiieedd oorr ddeeccllaarreedd oouuttssiiddee ooff aannyy ffuunnccttiioonn iiss vviissiibbllee ttoo aallll ffuunnccttiioonnss iinn tthhaatt ffiillee  FFuunnccttiioonn lleevveell ssccooppee DDeeccllaarriinngg vvaarriiaabblleess iinnssiiddee aa ffuunnccttiioonn ccaann bbee uusseedd iinn tthhee wwhhoollee ffuunnccttiioonn  BBlloocckk lleevveell ssccooppee VVaarriiaabblleess oorr iinntteeggeerrss ddeeccllaarreedd iinnssiiddee bblloocckk aarree uusseedd iinnssiiddee bblloocckk
  • 14. EExxaammppllee: BBlloocckk SSccooppee ffoorr (( iinntt ii == 00 ;; ii << 1100 ;; ii++++ ))  IItt iiss bblloocckk lleevveell ssccooppee ddeeccllaarreedd iinn ffoorr lloooopp  WWhheenn ffoorr iiss ffiinniisshheedd ““ ii ”” nnoo lloonnggeerr eexxiissttss
  • 15. EExxaammppllee: GGlloobbaall SSccooppee ##iinncclluuddee << iioossttrreeaamm..hh >> iinntt ii ;; vvooiidd ff (( vvooiidd )) ;; mmaaiinn (( )) {{ ii == 1100 ;; ccoouutt<<<< ““ wwiitthhiinn mmaaiinn ii == ““ <<<< ii ;; ff (( )) ;; }}
  • 16. EExxaammppllee: GGlloobbaall SSccooppee vvooiidd ff (( vvooiidd )) {{ ccoouutt<<<< ““ IInnssiiddee ffuunnccttiioonn ff ,, ii ==““ <<<< ii ;; ii == 2200 ;; }}
  • 17. EExxaammppllee:: CCaallll bbyy VVaalluuee ##iinncclluuddee <<iioossttrreeaamm..hh >> iinntt ff (( iinntt )) ;; mmaaiinn (( )) {{ iinntt ii == 1100 ;; ccoouutt <<<< ““IInn mmaaiinn ii == "" <<<< ii ;; ff (( ii )) ;; ccoouutt <<<< "" BBaacckk iinn mmaaiinn,, ii == "" <<<< ii ;; s }}
  • 18. iinntt ff (( iinntt ii )) {{ ccoouutt <<<< ""IInn ffuunnccttiioonn ff ,, ii == "" <<<< ii ;; ii **== 22 ;; ccoouutt <<<< ""IInn ffuunnccttiioonn ff ,, ii iiss nnooww == ““ <<<< ii ;; rreettuurrnn ii ;; }} EExxaammppllee:: CCaallll bbyy VVaalluuee
  • 19. double square (( ddoouubbllee xx )) {{ rreettuurrnn xx ** xx ;; }} mmaaiinn (( )) {{ ddoouubbllee nnuummbbeerr == 112233..445566 ;; ccoouutt <<<< ““ TThhee ssqquuaarree ooff ““ <<<< nnuummbbeerr <<<< ““ iiss ““<<<< ssqquuaarree (( nnuummbbeerr )) ;; ccoouutt <<<< ““ TThhee ccuurrrreenntt vvaalluuee ooff ““ <<<< nnuummbbeerr <<<< ““iiss ““ <<<< nnuummbbeerr ;; }} EExxaammppllee :: SSqquuaarree ooff aa NNuummbbeerr
  • 20. MMaatthh..hh ##iinncclluuddee << mmaatthh..hh >> ddoouubbllee ssqqrrtt (( ddoouubbllee ));; lloogg1100 ,, ppooww (( xxyy )) ,, ssiinn ,, ccooss ,, ttaann ……
  • 21. CCaallll bbyy RReeffeerreennccee  AA ffuunnccttiioonn iinn wwhhiicchh oorriiggiinnaall vvaalluuee ooff tthhee vvaarriiaabbllee iiss cchhaannggeedd  TToo ccaallll bbyy rreeffeerreennccee wwee ccaannnnoott ppaassss vvaalluuee,, wwee hhaavvee ttoo ppaassss mmeemmoorryy aaddddrreessss ooff vvaarriiaabbllee  ““&&”” iiss uusseedd ttoo ttaakkee tthhee aaddddrreessss ooff aa vvaarriiaabbllee
  • 22. EExxaammppllee:: CCaallll bbyy RReeffeerreennccee mmaaiinn (( )) {{ ddoouubbllee xx == 112233..445566 ;; ssqquuaarree (( &&xx )) ;; }} VVaalluuee ooff ‘‘xx’’ iiss nnoott ppaasssseedd ,, bbuutt tthhee mmeemmoorryy aaddddrreessss ooff ‘‘xx’’ iiss ppaasssseedd
  • 23. EExxaammppllee:: CCaallll bbyy RReeffeerreennccee x is a pointer to a variable double ssqquuaarree (( ddoouubbllee **xx )) {{ **xx == **xx ** **xx ;; }}
  • 24. PPooiinntteerrss  Pointers aarree uusseedd ttoo ppaassss aaddddrreessss ooff vvaarriiaabbllee ffoorr rreeffeerreennccee  WWee uussee ““ &&xx ”” ttoo sseenndd tthhee aaddddrreessss ooff ““ xx ““  TToo rreecceeiivvee tthhee aaddddrreessss wwee uussee ““ **xx ”” ((wwhhaatteevveerr ““ xx ”” ppooiinnttss ttoo))
  • 25. RReeccuurrssiivvee FFuunnccttiioonnss  Special function wwhhiicchh ccaann ccaallll iittsseellff xx1100 == xx ** xx99 xx99 == xx ** xx88 xx88 == xx ** xx77 …… …… xxnn == xx ** xxnn--11
  • 26. RReeccuurrssiivvee FFuunnccttiioonnss:: FFaaccttoorriiaall nn!! == nn ** ((nn--11)) ** ((nn--22)) ………….... 33 ** 22 ** 11 55!! == 55 ** 44 ** 33 ** 22 ** 11 44!! == 44 ** 33 ** 22 ** 11 55!! == 55 ** 44!! 00!! == 11
  • 27. RReeccuurrssiivvee FFuunnccttiioonnss:: FFaaccttoorriiaall lloonngg ffaaccttoorriiaall (( lloonngg nn )) {{ iiff ((nn ==== 11 )) rreettuurrnn (( nn )) ;; eellssee rreettuurrnn (( nn ** ffaaccttoorriiaall ((nn--11)) )) ;; }}
  • 28. EExxeerrcciissee TTrryy ttoo wwrriittee pprrooggrraamm ffoorr  FFiibboonnaaccccii sseerriieess  FFiinndd ‘‘ppoowweerr ooff nnuummbbeerr’’ uussiinngg rreeccuurrssiivvee tteecchhnniiqquuee
  • 29. EExxaammppllee TThhee FFiibboonnaaccccii SSeerriieess  SSeett ooff rreeccuurrssiivvee ccaallllss ttoo ffuunnccttiioonn ffiibboonnaaccccii f( 3 ) return + f( 2 ) f( 1 ) return + f( 1 ) f( 0 ) return 1 return 1 return 0
  • 30. MMaannaaggeemmeenntt IIssssuueess ooff CCoommppuutteerr TThheerree aarree ttwwoo iissssuueess iinnssiiddee aa ccoommppuutteerr  MMeemmoorryy oovveerrhheeaadd  SSttaacckk oovveerrhheeaadd
  • 31. PPrrooggrraammmmiinngg OOppttiioonnss  EElleeggaanntt ccooddee wwhheerree pprriiccee iiss nnoott ttoooo hhiigghh  EEffffiicciieenntt ccooddee wwhheerree pprriiccee iiss ttoooo hhiigghh
  • 32. WWhhaatt hhaavvee wwee DDoonnee TTooddaayy ……  HHeeaaddeerr FFiilleess – NNiiccee mmeecchhaanniissmm ooff ppuuttttiinngg aallll pprroottoottyyppeess aanndd ddeeffiinniittiioonnss ooff gglloobbaall ccoonnssttaannttss eettcc..  SSccooppee ooff vvaarriiaabblleess  FFuunnccttiioonnss – CCaallll bbyy vvaalluuee – CCaallll bbyy rreeffeerreennccee  RReeccuurrssiioonn