SlideShare a Scribd company logo
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

More Related Content

PPT
CS201- Introduction to Programming- Lecture 34
PPT
CS201- Introduction to Programming- Lecture 12
PPT
CS201- Introduction to Programming- Lecture 28
PPT
CS201- Introduction to Programming- Lecture 13
PPT
CS201- Introduction to Programming- Lecture 38
PPT
CS201- Introduction to Programming- Lecture 16
PPT
CS201- Introduction to Programming- Lecture 36
PPT
CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 34
CS201- Introduction to Programming- Lecture 12
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 13
CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 07

What's hot (19)

PPT
CS201- Introduction to Programming- Lecture 10
PPT
Edit data base menggunakan web
PPT
CS201- Introduction to Programming- Lecture 20
PPT
CS201- Introduction to Programming- Lecture 14
PPT
CS201- Introduction to Programming- Lecture 11
PPT
CS201- Introduction to Programming- Lecture 40
PPT
CS201- Introduction to Programming- Lecture 37
PPT
CS201- Introduction to Programming- Lecture 26
PPT
CS201- Introduction to Programming- Lecture 30
PPT
CS201- Introduction to Programming- Lecture 25
PPT
CS201- Introduction to Programming- Lecture 09
PPT
CS201- Introduction to Programming- Lecture 03
PPT
CS201- Introduction to Programming- Lecture 33
PPT
CS201- Introduction to Programming- Lecture 41
PPT
CS201- Introduction to Programming- Lecture 35
PPT
pengenalan perangkat keras komputer
PPT
Perangkat Keras Hardware
PPT
Perangkat keras komputer
PPT
Hardware
CS201- Introduction to Programming- Lecture 10
Edit data base menggunakan web
CS201- Introduction to Programming- Lecture 20
CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 11
CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 35
pengenalan perangkat keras komputer
Perangkat Keras Hardware
Perangkat keras komputer
Hardware
Ad

Viewers also liked (20)

PPT
CS201- Introduction to Programming- Lecture 43
PPS
ENG101- English Comprehension- Lecture 45
PPS
CS101- Introduction to Computing- Lecture 32
PPT
CS201- Introduction to Programming- Lecture 06
PPT
CS201- Introduction to Programming- Lecture 31
PPT
MGT101 - Financial Accounting- Lecture 40
PPT
MGT101 - Financial Accounting- Lecture 36
PPT
MGT101 - Financial Accounting- Lecture 33
PPS
ENG101- English Comprehension- Lecture 36
PPT
MGT101 - Financial Accounting- Lecture 41
PPS
CS101- Introduction to Computing- Lecture 23
PPT
MGT101 - Financial Accounting- Lecture 45
PPS
ENG101- English Comprehension- Lecture 42
PPT
CS201- Introduction to Programming- Lecture 39
PPT
CS201- Introduction to Programming- Lecture 32
DOC
MTH101 - Calculus and Analytical Geometry- Lecture 44
PPS
CS101- Introduction to Computing- Lecture 29
PPS
CS101- Introduction to Computing- Lecture 37
PPS
ENG101- English Comprehension- Lecture 40
PPS
ENG101- English Comprehension- Lecture 35
CS201- Introduction to Programming- Lecture 43
ENG101- English Comprehension- Lecture 45
CS101- Introduction to Computing- Lecture 32
CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 31
MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 36
MGT101 - Financial Accounting- Lecture 33
ENG101- English Comprehension- Lecture 36
MGT101 - Financial Accounting- Lecture 41
CS101- Introduction to Computing- Lecture 23
MGT101 - Financial Accounting- Lecture 45
ENG101- English Comprehension- Lecture 42
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 32
MTH101 - Calculus and Analytical Geometry- Lecture 44
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 37
ENG101- English Comprehension- Lecture 40
ENG101- English Comprehension- Lecture 35
Ad

Similar to CS201- Introduction to Programming- Lecture 15 (15)

PPT
CS201- Introduction to Programming- Lecture 23
PPT
CS201- Introduction to Programming- Lecture 45
PPT
CS201- Introduction to Programming- Lecture 04
PPT
CS201- Introduction to Programming- Lecture 44
PPT
CS201- Introduction to Programming- Lecture 08
PPT
MS Unit-6
PPT
CS201- Introduction to Programming- Lecture 21
PPT
CS201- Introduction to Programming- Lecture 27
PPT
CS201- Introduction to Programming- Lecture 24
PPT
CS201- Introduction to Programming- Lecture 22
PPT
Penetration testing: A proactive approach to secure computing - Eric Vanderbu...
PDF
Contrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressed
PDF
TOP Downloaded Papers (January)--International Journal of Computer Networks &...
PPT
Ethernet Passive Optical Network
PPT
21 High-quality programming code construction part-ii
CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 04
CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 08
MS Unit-6
CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 22
Penetration testing: A proactive approach to secure computing - Eric Vanderbu...
Contrarrazoes ro vinculo empregaticio reclamada ilovepdf-compressed
TOP Downloaded Papers (January)--International Journal of Computer Networks &...
Ethernet Passive Optical Network
21 High-quality programming code construction part-ii

CS201- Introduction to Programming- Lecture 15