SlideShare une entreprise Scribd logo
1  sur  32
Introduction ttoo PPrrooggrraammmmiinngg 
LLeeccttuurree 1155
IInn TTooddaayy’’ss LLeeccttuurree 
 PPooiinntteerrss aanndd AArrrraayyss 
MMaanniippuullaattiioonnss 
 PPooiinntteerrss EExxpprreessssiioonn 
 PPooiinntteerrss AArriitthhmmeettiicc 
 MMuullttiiddiimmeennssiioonnaall AArrrraayyss 
 PPooiinntteerr SSttrriinngg aanndd AArrrraayy
Pointers aanndd AArrrraayyss 
int y [ 10 ] ; Starting Address of Array y [0] 
00 
11 
22 
33 
44 
55 
66 
77 
88 
99 
[1] 
[2] 
[3] 
[4] 
[5] 
[6] 
[7] 
[8] 
[9]
The nnaammee ooff tthhee aarrrraayy iiss lliikkee aa 
ppooiinntteerr wwhhiicchh ccoonnttaaiinn tthhee 
aaddddrreessss ooff tthhee ffiirrsstt eelleemmeenntt..
Declaration of aa PPooiinntteerr VVaarriiaabbllee 
iinntt yy [[ 1100 ]] ;; 
iinntt **yyppttrr ;; 
yyppttrr == yy ;; 
yptr is a pointer to integer
Declaration of aa PPooiinntteerr VVaarriiaabbllee 
00 
11 
22 
33 
44 
55 
66 
77 
88 
99 
y [ 3 ] 
[0] 
[1] 
[2] 
[3] 
[4] 
[5] 
[6] 
[7] 
[8] 
[9]
iinntt yy [[ 1100 ]] ;; 
iinntt **yyppttrr ;; 
yyppttrr == yy ;; 
yyppttrr ++++ ;;
location 
3000 3004 3008 3012 3016 
y[0] y[1] y[2] y[3] y[4] 
pointer variable yPtr
IInn tthhiiss ccaassee yyppttrr iiss aa ppooiinntteerr 
ttoo iinntteeggeerr ssoo nnooww wwhheenn wwee 
iinnccrreemmeenntt yyppttrr iitt ppooiinnttss ttoo 
tthhee nneexxtt iinntteeggeerr
EExxaammppllee 11 
##iinncclluuddee<<iioossttrreeaamm..hh>> 
mmaaiinn (( )) 
{{ 
iinntt yy [[ 1100 ]] ;; 
iinntt **yyppttrr == yy ;; 
yyppttrr == yy ;; 
ccoouutt <<<< yyppttrr ;; 
yyppttrr ++++ ;; 
ccoouutt <<<< yyppttrr ;; 
}}
yyppttrr == yy ;; 
iiss ssaammee aass 
yyppttrr == &&yy [[ 00 ]] ;; 
………….... 
yyppttrr == &&yy [[ 22 ]] ;;
EExxaammppllee 22 
##iinncclluuddee<<iioossttrreeaamm..hh>> 
mmaaiinn (( )) 
{{ 
iinntt yy [[ 1100 ]] ;; 
iinntt **yyppttrr ;; 
yyppttrr == yy ;; 
ccoouutt <<<< yyppttrr ;; 
yyppttrr ++++ ;; 
ccoouutt <<<< **yyppttrr ;; 
}}
mmaaiinn (( )) 
{{ 
iinntt xx == 1100 ;; 
iinntt **yyppttrr ;; 
yyppttrr == &&xx ;; 
ccoouutt <<<< yyppttrr ;; 
ccoouutt <<<< **yyppttrr ;; 
**yyppttrr ++++ ;; 
}} 
EExxaammppllee 33 
increment whatever yptr points to
PPooiinntteerr AArriitthhmmeettiicc 
**yyppttrr ++ 33 ;; 
ccoouutt <<<< **yyppttrr ;; 
**yyppttrr ++== 33 ;; 
This Is an Expression
PPooiinntteerr AArriitthhmmeettiicc 
yyppttrr == &&xx ;; 
yyppttrr ++++ ;;
PPooiinntteerr AArriitthhmmeettiicc 
iinntt xx ==1100 ;; 
iinntt **yyppttrr ;; 
yyppttrr == &&xx ;; 
**yyppttrr ++== 33 ;; 
yyppttrr ++== 33 ;;
DDeeccrreemmeennttiinngg 
**yyppttrr ----
PPooiinntteerr AArriitthhmmeettiicc 
iinntt **pp11 ,,**pp22;; 
…….... 
pp11 ++ pp22 ;; 
Error
PPooiinntteerr AArriitthhmmeettiicc 
iinntt yy [[ 1100 ]] ,, **yy11 ,, **yy22 ;; 
yy11 == &&yy [[ 00 ]] ;; 
yy22 == &&yy [[ 33 ]] ;; 
ccoouutt <<<< yy22 -- yy11 ;;
PPooiinntteerr AArriitthhmmeettiicc 
iinntt yy [[ 1100 ]] ;; 
iinntt **yyppttrr ;; 
yyppttrr == yy [[ 55 ]] ;; 
ccoouutt <<<< **(( yyppttrr ++ 55 )) ;;
PPooiinntteerr CCoommppaarriissoonn 
iiff (( yy11 >> yy22 )) 
iiff (( yy11 >>== yy22 )) 
iiff (( yy11 ==== yy22 ))
PPooiinntteerr CCoommppaarriissoonn 
iiff (( **yy11 >> **yy22 ))
EExxaammppllee 
iinntt yy [[ 1100 ]] ;; 
iinntt **yyppttrr ;; 
yyppttrr == yy ;; 
ccoouutt <<<< yy [[ 55 ]] ;; 
ccoouutt <<<< (( yyppttrr ++ 55 )) ;; 
ccoouutt <<<< **(( yyppttrr ++ 55 )) ;;
EExxaammppllee 
iinntt qquuee [[ 1100 ]] ;; 
iinntt yy [[ 1100 ]];; 
iinntt **yyppttrr ;; 
yyppttrr == yy ;; 
yyppttrr == qquuee ;;
location 
3000 3004 3008 3012 3016 
v[0] v[1] v[2] v[3] v[4] 
pointer variable vPtr
SSttrriinnggss
String IInniittiiaalliizzaattiioonn 
cchhaarr nnaammee [[ 2200 ]] ;; 
nnaammee [[ 00 ]] == ‘‘AA’’ ;; 
nnaammee [[ 11 ]] == ‘‘mm’’ ;; 
nnaammee [[ 22 ]] == ‘‘ii’’ ;; 
nnaammee [[ 33 ]] == ‘‘rr’’ ;; 
nnaammee [[ 44 ]] == ‘‘00’’ ;;
String IInniittiiaalliizzaattiioonn 
SSttrriinnggss iiss aallwwaayyss 
tteerrmmiinnaatteedd wwiitthh 00
String IInniittiiaalliizzaattiioonn 
cchhaarr nnaammee [[ 2200 ]] == ““AAmmiirr”” ;; 
AArrrraayy mmuusstt bbee oonnee cchhaarraacctteerr 
ssppaaccee llaarrggeerr tthhaann tthhee nnuummbbeerr ooff 
pprriinnttaabbllee cchhaarraacctteerr wwhhiicchh aarree ttoo 
bbee ssttoorreedd..
EExxaammppllee 44 
cchhaarr ssttrriinngg11 [[ 2200 ]] == ““AAmmiirr””;; 
cchhaarr ssttrriinngg22 [[ 2200 ]] ;; 
cchhaarr **ppttrrAA, **ppttrrBB ;; 
pprrttAA == ssttrriinngg11 ;; 
pprrttBB == ssttrriinngg22 ;; 
wwhhiillee (( **ppttrrAA !!== ‘‘00’’ )) 
{{ 
**ppttrrBB++++ == **ppttrrAA++++;; 
}} 
**ppttrrBB == ‘‘00’’ ;;
SSttrriinngg CCooppyy 
FFuunnccttiioonn 
mmyySSttrriinnggCCooppyy (( cchhaarr **ddeessttiinnaattiioonn , ccoonnsstt cchhaarr **ssoouurrccee )) 
{{ 
wwhhiillee (( **ssoouurrccee !!== ‘‘00’’ )) 
{{ 
**ddeessttiinnaattiioonn++++ == **ssoouurrccee++++ ;; 
}} 
**ddeessttiinnaattiioonn == ‘‘00’’ ;; 
}}
IInn TTooddaayy’’ss 
LLeeccttuurree 
PPooiinntteerrss aanndd AArrrraayyss 
PPooiinntteerr AArriitthhmmeettiicc 
MMaanniippuullaattiioonn ooff AArrrraayyss 
SSttrriinngg AArrrraayyss

Contenu connexe

Tendances

pengenalan perangkat keras komputer
pengenalan perangkat keras komputerpengenalan perangkat keras komputer
pengenalan perangkat keras komputer
zee120196
 

Tendances (19)

CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10
 
Edit data base menggunakan web
Edit data base menggunakan webEdit data base menggunakan web
Edit data base menggunakan web
 
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 14
CS201- Introduction to Programming- Lecture 14CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 14
 
CS201- Introduction to Programming- Lecture 11
CS201- Introduction to Programming- Lecture 11CS201- Introduction to Programming- Lecture 11
CS201- Introduction to Programming- Lecture 11
 
CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 40CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 40
 
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 26
CS201- Introduction to Programming- Lecture 26CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26
 
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 25
CS201- Introduction to Programming- Lecture 25CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25
 
CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 09CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 09
 
CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03
 
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 41
CS201- Introduction to Programming- Lecture 41CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41
 
CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35
 
pengenalan perangkat keras komputer
pengenalan perangkat keras komputerpengenalan perangkat keras komputer
pengenalan perangkat keras komputer
 
Perangkat Keras Hardware
Perangkat Keras HardwarePerangkat Keras Hardware
Perangkat Keras Hardware
 
Perangkat keras komputer
Perangkat keras komputerPerangkat keras komputer
Perangkat keras komputer
 
Hardware
HardwareHardware
Hardware
 

En vedette

En vedette (20)

CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43
 
ENG101- English Comprehension- Lecture 45
ENG101- English Comprehension- Lecture 45ENG101- English Comprehension- Lecture 45
ENG101- English Comprehension- Lecture 45
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32
 
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 31
CS201- Introduction to Programming- Lecture 31CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31
 
MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40
 
MGT101 - Financial Accounting- Lecture 36
MGT101 - Financial Accounting- Lecture 36MGT101 - Financial Accounting- Lecture 36
MGT101 - Financial Accounting- Lecture 36
 
MGT101 - Financial Accounting- Lecture 33
MGT101 - Financial Accounting- Lecture 33MGT101 - Financial Accounting- Lecture 33
MGT101 - Financial Accounting- Lecture 33
 
ENG101- English Comprehension- Lecture 36
ENG101- English Comprehension- Lecture 36ENG101- English Comprehension- Lecture 36
ENG101- English Comprehension- Lecture 36
 
MGT101 - Financial Accounting- Lecture 41
MGT101 - Financial Accounting- Lecture 41MGT101 - Financial Accounting- Lecture 41
MGT101 - Financial Accounting- Lecture 41
 
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 45
MGT101 - Financial Accounting- Lecture 45MGT101 - Financial Accounting- Lecture 45
MGT101 - Financial Accounting- Lecture 45
 
ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42
 
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39
 
CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32
 
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
 
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29
 
CS101- Introduction to Computing- Lecture 37
CS101- Introduction to Computing- Lecture 37CS101- Introduction to Computing- Lecture 37
CS101- Introduction to Computing- Lecture 37
 
ENG101- English Comprehension- Lecture 40
ENG101- English Comprehension- Lecture 40ENG101- English Comprehension- Lecture 40
ENG101- English Comprehension- Lecture 40
 
ENG101- English Comprehension- Lecture 35
ENG101- English Comprehension- Lecture 35ENG101- English Comprehension- Lecture 35
ENG101- English Comprehension- Lecture 35
 

Similaire à CS201- Introduction to Programming- Lecture 15

Similaire à CS201- Introduction to Programming- Lecture 15 (15)

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 45
CS201- Introduction to Programming- Lecture 45CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45
 
CS201- Introduction to Programming- Lecture 04
CS201- Introduction to Programming- Lecture 04CS201- Introduction to Programming- Lecture 04
CS201- Introduction to Programming- Lecture 04
 
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 08
CS201- Introduction to Programming- Lecture 08CS201- Introduction to Programming- Lecture 08
CS201- Introduction to Programming- Lecture 08
 
MS Unit-6
MS Unit-6MS Unit-6
MS Unit-6
 
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 27
CS201- Introduction to Programming- Lecture 27CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27
 
CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24
 
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22
 
Penetration testing: A proactive approach to secure computing - Eric Vanderbu...
Penetration testing: A proactive approach to secure computing - Eric Vanderbu...Penetration testing: A proactive approach to secure computing - Eric Vanderbu...
Penetration testing: A proactive approach to secure computing - Eric Vanderbu...
 
Contrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressed
Contrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressedContrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressed
Contrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressed
 
TOP Downloaded Papers (January)--International Journal of Computer Networks &...
TOP Downloaded Papers (January)--International Journal of Computer Networks &...TOP Downloaded Papers (January)--International Journal of Computer Networks &...
TOP Downloaded Papers (January)--International Journal of Computer Networks &...
 
Ethernet Passive Optical Network
Ethernet Passive Optical NetworkEthernet Passive Optical Network
Ethernet Passive Optical Network
 
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
 

Dernier

Immunologian perusteet: valkosolutyyppien yhteistyö, elinsiirrot, allergia
Immunologian perusteet: valkosolutyyppien yhteistyö, elinsiirrot, allergiaImmunologian perusteet: valkosolutyyppien yhteistyö, elinsiirrot, allergia
Immunologian perusteet: valkosolutyyppien yhteistyö, elinsiirrot, allergia
Pasi Vilpas
 

Dernier (9)

Koululaiset, opiskelija, oppijat ja lapset sekä tutkinnot
Koululaiset, opiskelija, oppijat ja lapset sekä tutkinnotKoululaiset, opiskelija, oppijat ja lapset sekä tutkinnot
Koululaiset, opiskelija, oppijat ja lapset sekä tutkinnot
 
Aikuiskoulutus, jatkuva oppiminen, elinikäinen oppiminen ja henkilöstökoulutus
Aikuiskoulutus, jatkuva oppiminen, elinikäinen oppiminen ja henkilöstökoulutusAikuiskoulutus, jatkuva oppiminen, elinikäinen oppiminen ja henkilöstökoulutus
Aikuiskoulutus, jatkuva oppiminen, elinikäinen oppiminen ja henkilöstökoulutus
 
Jedhi Malee (just do it).pdf
Jedhi Malee             (just do it).pdfJedhi Malee             (just do it).pdf
Jedhi Malee (just do it).pdf
 
Koulutuksen rahoitus, tulot, menot ja talous
Koulutuksen rahoitus, tulot, menot ja talousKoulutuksen rahoitus, tulot, menot ja talous
Koulutuksen rahoitus, tulot, menot ja talous
 
Kasvatus, koulutus, opetus ja osaaminen Suomessa
Kasvatus, koulutus, opetus ja osaaminen SuomessaKasvatus, koulutus, opetus ja osaaminen Suomessa
Kasvatus, koulutus, opetus ja osaaminen Suomessa
 
Tutkimus-, kehittämis- ja innovaatiotoiminnan rahoitus
Tutkimus-, kehittämis- ja innovaatiotoiminnan rahoitusTutkimus-, kehittämis- ja innovaatiotoiminnan rahoitus
Tutkimus-, kehittämis- ja innovaatiotoiminnan rahoitus
 
Immunologian perusteet: valkosolutyyppien yhteistyö, elinsiirrot, allergia
Immunologian perusteet: valkosolutyyppien yhteistyö, elinsiirrot, allergiaImmunologian perusteet: valkosolutyyppien yhteistyö, elinsiirrot, allergia
Immunologian perusteet: valkosolutyyppien yhteistyö, elinsiirrot, allergia
 
Koulutuksen palkat ja kustannukset sekä koulutuksen ansiot
Koulutuksen palkat ja kustannukset sekä koulutuksen ansiotKoulutuksen palkat ja kustannukset sekä koulutuksen ansiot
Koulutuksen palkat ja kustannukset sekä koulutuksen ansiot
 
Oppimateriaaleihin, menetelmiin ja sovelluksiin tutustuminen 2.5.24
Oppimateriaaleihin, menetelmiin ja sovelluksiin tutustuminen 2.5.24Oppimateriaaleihin, menetelmiin ja sovelluksiin tutustuminen 2.5.24
Oppimateriaaleihin, menetelmiin ja sovelluksiin tutustuminen 2.5.24
 

CS201- Introduction to Programming- Lecture 15