SlideShare a Scribd company logo
1 of 22
Introduction ttoo PPrrooggrraammmmiinngg 
LLeeccttuurree 1166
IInn TTooddaayy 
LLeeccttuurree 
CCoonncclluuddee tthhee llaasstt ddiissccuussssiioonn 
MMuullttii--ddiimmeennssiioonnaall AArrrraayyss 
PPooiinntteerrss ttoo PPooiinntteerrss
EExxaammppllee 11 
cchhaarr mmyyNNaammee [[ ]] == ““AAmmiirr”” ;; 
cchhaarr **mmyyNNaammeePPttrr == ““AAmmiirr”” ;;
Multi-ddiimmeennssiioonnaall AArrrraayyss 
cchhaarr mmuullttii [[ 55 ]] [[ 1100 ]] ;;
Multi-dimensional AArrrraayy iinn 
MMeemmoorryy 
Placed sequentially in the memory 
[0] [1] [2] [3] [4] [0] [1] [2] [3] [4] [0] [1] [2] [3] [4] 
11 22 33 44 1100 77 99 1111 1144 1100 1177 2255 3399 4455 5588 
1st row 
1st col 
2nd row 
1st col 
3rd row 
1st col
DDeerreeffeerreenncciinngg aarrrraayy 
eelleemmeenntt 
mmuullttii [[ 22 ]] [[ 33 ]]
**mmuullttii 
??
EExxaammppllee 22 
##iinncclluuddee<<iioossttrreeaamm..hh>> 
mmaaiinn (( )) 
{{ 
cchhaarr mmuullttii [[ 55 ]] [[ 1100 ]] ;; 
ccoouutt <<<< mmuullttii <<<< eennddll ;; 
ccoouutt <<<< **mmuullttii ;; 
ccoouutt <<<< ****mmuullttii ;; 
}}
mmuullttii ++ 33 
**(( mmuullttii ++ 33 )) 
**(( mmuullttii ++ 33 )) ++ 33 
**((**(( mmuullttii ++ 33 )) ++ 33 ))
EExxaammppllee 33 
mmaaiinn (( )) 
{{ 
iinntt mmuullttii [[ 55 ]] [[ 66 ]] ;; 
iinntt rrooww ,, ccooll ;; 
iinntt **ppttrr ;; 
ppttrr == **mmuullttii ;; 
ffoorr (( rrooww == 00 ;; rrooww << 55 ;; rrooww ++++ )) 
{{ 
ffoorr (( ccooll == 00 ;; ccooll << 1100 ;; ccooll ++++ )) 
{{ 
mmuullttii [[ rrooww ]] [[ ccooll ]] == rrooww ** ccooll ;; 
}} 
}}
EExxaammppllee 33 
ffoorr (( rrooww == 00 ;; rrooww << 55 ;; rrooww ++++ )) 
{{ 
ffoorr (( ccooll == 00 ;; ccooll << 1100 ;; ccooll ++++)) 
{{ 
ccoouutt <<<< **(( ppttrr ++++ )) <<<< ““ ””;; 
}} 
ccoouutt <<<< eennddll ;; 
}} 
}}
PPooiinntteerr ttoo aa 
PPooiinntteerr
AArrrraayy ooff PPooiinntteerrss
AArrrraayy ooff 
PPooiinntteerrss 
cchhaarr **mmyyAArrrraayy [[ 1100 ]] ;; 
myArray is an array of 10 pointer to 
character
IInniittiiaalliizzaattiioonn 
cchhaarr **mmyyAArrrraayy [[ ]] == {{ ““AAmmiirr ”” ,, ““ JJaahhaannggiirr ”” }} ;;
Storing Pointers iinn AArrrraayy ooff 
PPooiinntteerrss 
iinntt **pp11 ,, **pp22 ,, **pp33 ;; 
iinntt **bb [[ 33 ]] ;; 
bb [[ 00 ]] == pp11 ;; 
bb [[ 11 ]] == pp22 ;; 
bb [[ 22 ]] == pp33 ;;
Command LLiinnee AArrgguummeennttss 
aarrggcc 
aarrggvv 
‘‘aarrggcc’’ ssttaannddss ffoorr aa ccoouunntt ooff tthhee nnuummbbeerr 
ooff aarrgguummeennttss 
‘‘aarrggvv’’ ssttaannddss ffoorr aa vveeccttoorr ooff aarrgguummeennttss
EExxaammppllee 44 
mmaaiinn (( iinntt aarrggcc ,, cchhaarr ****aarrggvv )) 
{{ 
ccoouutt <<<< aarrggcc <<<< ""nn““ <<<< **aarrggvv ;; 
}}
EExxaammppllee 55 
mmaaiinn (( )) 
{{ 
ccoonnsstt cchhaarr **ssuuiitt [[ 44 ]]== {{ ""SSppaaddeess““ ,, ""HHeeaarrttss““ ,, 
""DDiiaammoonnddss““ ,, 
""CClluubbss““ }} ;; 
ccoonnsstt cchhaarr **ffaaccee [[ 1133 ]] == {{ ""AAccee““ ,, ""DDeeuuccee““ ,, ""TThhrreeee““ ,, ""FFoouurr"",, 
""FFiivvee““ ,, ""SSiixx““ ,, ""SSeevveenn““ ,, 
""EEiigghhtt““ ,, 
""NNiinnee““ ,, ""TTeenn““ ,, ""JJaacckk““ ,, ""QQuueeeenn““ ,, 
""KKiinngg"" }} ;; 
iinntt ddeecckk [[ 44 ]] [[ 1133 ]] == {{ 00 }} ;; 
ssrraanndd (( ttiimmee (( 00 )) )) ;; 
sshhuuffffllee (( ddeecckk )) ;; 
ddeeaall (( ddeecckk ,, ffaaccee ,, ssuuiitt )) ;;
SShhuuffffllee FFuunnccttiioonnss 
vvooiidd sshhuuffffllee (( iinntt wwDDeecckk [[ ]] [[ 1133 ]] )) 
{{ 
iinntt rrooww ,, ccoolluummnn ,, ccaarrdd ;; 
ffoorr (( ccaarrdd == 11 ;; ccaarrdd <<== 5522 ;; ccaarrdd ++++ )) 
{{ 
ddoo 
{{ 
rrooww == rraanndd (( )) %% 44 ;; 
ccoolluummnn == rraanndd (( )) %% 1133 ;; 
}} 
wwhhiillee(( wwDDeecckk[[ rrooww ]]|| ccoolluummnn ]] !!== 00 )) ;; 
wwDDeecckk [[ rrooww ]] [[ ccoolluummnn ]] == ccaarrdd ;; 
}} 
}}
DDeeaall FFuunnccttiioonn 
vvooiidd ddeeaall (( ccoonnsstt iinntt wwDDeecckk [[ ]] [[ 1133 ]] ,, ccoonnsstt cchhaarr **wwFFaaccee [[ ]] ,, ccoonnsstt cchhaarr **wwSSuuiitt [[ ]] )) 
{{ 
iinntt ccaarrdd ,, rrooww ,, ccoolluummnn ;; 
ffoorr (( ccaarrdd == 11 ;; ccaarrdd <<== 5522 ;; ccaarrdd ++++ )) 
{{ 
ffoorr (( rrooww == 00 ;; rrooww <<== 33 ;; rrooww++++ )) 
{{ 
ffoorr (( ccoolluummnn == 00 ;; ccoolluummnn <<== 1122 ;; ccoolluummnn ++++ )) 
{{ 
iiff (( wwDDeecckk [[ rrooww ]] [[ ccoolluummnn ]] ==== ccaarrdd )) 
//// PPrriinntt tthhee ffaaccee aanndd ssuuiitt ooff tthhee ccaarrdd 
//// bbrreeaakk oouutt ooff llooooppss 
}} 
}} 
}} 
}}
WWhhaatt wwee hhaavvee ddoonnee 
ttooddaayy 
 MMuullttii--ddiimmeennssiioonnaall AArrrraayyss 
 PPooiinntteerrss ttoo PPooiinntteerrss 
 AArrrraayyss ooff PPooiinntteerrss 
 CCoommmmaanndd LLiinnee 
AArrgguummeennttss 
 CCoommpprreehheennssiivvee EExxaammppllee

More Related Content

What's hot

CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 40CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 40Bilal Ahmed
 
Edit data base menggunakan web
Edit data base menggunakan webEdit data base menggunakan web
Edit data base menggunakan webhaviedz miftah
 
CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 06Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 04
CS201- Introduction to Programming- Lecture 04CS201- Introduction to Programming- Lecture 04
CS201- Introduction to Programming- Lecture 04Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 08
CS201- Introduction to Programming- Lecture 08CS201- Introduction to Programming- Lecture 08
CS201- Introduction to Programming- Lecture 08Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 14CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 14Bilal Ahmed
 
Tietoturvahyökkaysyritysten havaitseminen ja seuranta
Tietoturvahyökkaysyritysten havaitseminen ja seurantaTietoturvahyökkaysyritysten havaitseminen ja seuranta
Tietoturvahyökkaysyritysten havaitseminen ja seurantaOtto Kekäläinen
 
CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42Bilal Ahmed
 

What's hot (20)

CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 40CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 40
 
Edit data base menggunakan web
Edit data base menggunakan webEdit data base menggunakan web
Edit data base menggunakan web
 
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 36
CS201- Introduction to Programming- Lecture 36CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36
 
CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10
 
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 26
CS201- Introduction to Programming- Lecture 26CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26
 
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 04
CS201- Introduction to Programming- Lecture 04CS201- Introduction to Programming- Lecture 04
CS201- Introduction to Programming- Lecture 04
 
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 35
CS201- Introduction to Programming- Lecture 35CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35
 
Ankit
AnkitAnkit
Ankit
 
CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 14CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 14
 
Mba ebooks
Mba ebooksMba ebooks
Mba ebooks
 
Angular.js
Angular.jsAngular.js
Angular.js
 
Tietoturvahyökkaysyritysten havaitseminen ja seuranta
Tietoturvahyökkaysyritysten havaitseminen ja seurantaTietoturvahyökkaysyritysten havaitseminen ja seuranta
Tietoturvahyökkaysyritysten havaitseminen ja seuranta
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42
 
Tres clases de obras. 1º obras de la carne
Tres clases de obras. 1º obras de la carneTres clases de obras. 1º obras de la carne
Tres clases de obras. 1º obras de la carne
 
Metoda bisecţiei
Metoda bisecţieiMetoda bisecţiei
Metoda bisecţiei
 

Viewers also liked

CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43Bilal Ahmed
 
ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19Bilal Ahmed
 
ENG101- English Comprehension- Lecture 30
ENG101- English Comprehension- Lecture 30ENG101- English Comprehension- Lecture 30
ENG101- English Comprehension- Lecture 30Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 33
MGT101 - Financial Accounting- Lecture 33MGT101 - Financial Accounting- Lecture 33
MGT101 - Financial Accounting- Lecture 33Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32Bilal Ahmed
 
ENG101- English Comprehension- Lecture 40
ENG101- English Comprehension- Lecture 40ENG101- English Comprehension- Lecture 40
ENG101- English Comprehension- Lecture 40Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 41
MGT101 - Financial Accounting- Lecture 41MGT101 - Financial Accounting- Lecture 41
MGT101 - Financial Accounting- Lecture 41Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 30
MGT101 - Financial Accounting- Lecture 30MGT101 - Financial Accounting- Lecture 30
MGT101 - Financial Accounting- Lecture 30Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 36
MGT101 - Financial Accounting- Lecture 36MGT101 - Financial Accounting- Lecture 36
MGT101 - Financial Accounting- Lecture 36Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35Bilal Ahmed
 

Viewers also liked (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 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 31
CS201- Introduction to Programming- Lecture 31CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31
 
CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19
 
ENG101- English Comprehension- Lecture 30
ENG101- English Comprehension- Lecture 30ENG101- English Comprehension- Lecture 30
ENG101- English Comprehension- Lecture 30
 
CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38
 
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 32
CS201- Introduction to Programming- Lecture 32CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32
 
CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44CS101- Introduction to Computing- Lecture 44
CS101- Introduction to Computing- Lecture 44
 
MGT101 - Financial Accounting- Lecture 33
MGT101 - Financial Accounting- Lecture 33MGT101 - Financial Accounting- Lecture 33
MGT101 - Financial Accounting- Lecture 33
 
CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32
 
ENG101- English Comprehension- Lecture 40
ENG101- English Comprehension- Lecture 40ENG101- English Comprehension- Lecture 40
ENG101- English Comprehension- Lecture 40
 
MGT101 - Financial Accounting- Lecture 41
MGT101 - Financial Accounting- Lecture 41MGT101 - Financial Accounting- Lecture 41
MGT101 - Financial Accounting- Lecture 41
 
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22
 
MGT101 - Financial Accounting- Lecture 30
MGT101 - Financial Accounting- Lecture 30MGT101 - Financial Accounting- Lecture 30
MGT101 - Financial Accounting- Lecture 30
 
MGT101 - Financial Accounting- Lecture 36
MGT101 - Financial Accounting- Lecture 36MGT101 - Financial Accounting- Lecture 36
MGT101 - Financial Accounting- Lecture 36
 
MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40MGT101 - Financial Accounting- Lecture 40
MGT101 - Financial Accounting- Lecture 40
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35
 

Similar to CS201- Introduction to Programming- Lecture 16

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-iimaznabili
 
CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 09CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 09Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25CS201- Introduction to Programming- Lecture 25
CS201- Introduction to Programming- Lecture 25Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18Bilal Ahmed
 
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-compressedLeve Desejo
 

Similar to CS201- Introduction to Programming- Lecture 16 (14)

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
 
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 09
CS201- Introduction to Programming- Lecture 09CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 09
 
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 03
CS201- Introduction to Programming- Lecture 03CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03
 
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 45
CS201- Introduction to Programming- Lecture 45CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45
 
MS Unit-6
MS Unit-6MS Unit-6
MS Unit-6
 
CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38
 
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 37
CS201- Introduction to Programming- Lecture 37CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37
 
CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18
 
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
 
IDRC Davos, oral, 250814
IDRC Davos, oral, 250814IDRC Davos, oral, 250814
IDRC Davos, oral, 250814
 

CS201- Introduction to Programming- Lecture 16

  • 2. IInn TTooddaayy LLeeccttuurree CCoonncclluuddee tthhee llaasstt ddiissccuussssiioonn MMuullttii--ddiimmeennssiioonnaall AArrrraayyss PPooiinntteerrss ttoo PPooiinntteerrss
  • 3. EExxaammppllee 11 cchhaarr mmyyNNaammee [[ ]] == ““AAmmiirr”” ;; cchhaarr **mmyyNNaammeePPttrr == ““AAmmiirr”” ;;
  • 4. Multi-ddiimmeennssiioonnaall AArrrraayyss cchhaarr mmuullttii [[ 55 ]] [[ 1100 ]] ;;
  • 5. Multi-dimensional AArrrraayy iinn MMeemmoorryy Placed sequentially in the memory [0] [1] [2] [3] [4] [0] [1] [2] [3] [4] [0] [1] [2] [3] [4] 11 22 33 44 1100 77 99 1111 1144 1100 1177 2255 3399 4455 5588 1st row 1st col 2nd row 1st col 3rd row 1st col
  • 8. EExxaammppllee 22 ##iinncclluuddee<<iioossttrreeaamm..hh>> mmaaiinn (( )) {{ cchhaarr mmuullttii [[ 55 ]] [[ 1100 ]] ;; ccoouutt <<<< mmuullttii <<<< eennddll ;; ccoouutt <<<< **mmuullttii ;; ccoouutt <<<< ****mmuullttii ;; }}
  • 9. mmuullttii ++ 33 **(( mmuullttii ++ 33 )) **(( mmuullttii ++ 33 )) ++ 33 **((**(( mmuullttii ++ 33 )) ++ 33 ))
  • 10. EExxaammppllee 33 mmaaiinn (( )) {{ iinntt mmuullttii [[ 55 ]] [[ 66 ]] ;; iinntt rrooww ,, ccooll ;; iinntt **ppttrr ;; ppttrr == **mmuullttii ;; ffoorr (( rrooww == 00 ;; rrooww << 55 ;; rrooww ++++ )) {{ ffoorr (( ccooll == 00 ;; ccooll << 1100 ;; ccooll ++++ )) {{ mmuullttii [[ rrooww ]] [[ ccooll ]] == rrooww ** ccooll ;; }} }}
  • 11. EExxaammppllee 33 ffoorr (( rrooww == 00 ;; rrooww << 55 ;; rrooww ++++ )) {{ ffoorr (( ccooll == 00 ;; ccooll << 1100 ;; ccooll ++++)) {{ ccoouutt <<<< **(( ppttrr ++++ )) <<<< ““ ””;; }} ccoouutt <<<< eennddll ;; }} }}
  • 12. PPooiinntteerr ttoo aa PPooiinntteerr
  • 14. AArrrraayy ooff PPooiinntteerrss cchhaarr **mmyyAArrrraayy [[ 1100 ]] ;; myArray is an array of 10 pointer to character
  • 15. IInniittiiaalliizzaattiioonn cchhaarr **mmyyAArrrraayy [[ ]] == {{ ““AAmmiirr ”” ,, ““ JJaahhaannggiirr ”” }} ;;
  • 16. Storing Pointers iinn AArrrraayy ooff PPooiinntteerrss iinntt **pp11 ,, **pp22 ,, **pp33 ;; iinntt **bb [[ 33 ]] ;; bb [[ 00 ]] == pp11 ;; bb [[ 11 ]] == pp22 ;; bb [[ 22 ]] == pp33 ;;
  • 17. Command LLiinnee AArrgguummeennttss aarrggcc aarrggvv ‘‘aarrggcc’’ ssttaannddss ffoorr aa ccoouunntt ooff tthhee nnuummbbeerr ooff aarrgguummeennttss ‘‘aarrggvv’’ ssttaannddss ffoorr aa vveeccttoorr ooff aarrgguummeennttss
  • 18. EExxaammppllee 44 mmaaiinn (( iinntt aarrggcc ,, cchhaarr ****aarrggvv )) {{ ccoouutt <<<< aarrggcc <<<< ""nn““ <<<< **aarrggvv ;; }}
  • 19. EExxaammppllee 55 mmaaiinn (( )) {{ ccoonnsstt cchhaarr **ssuuiitt [[ 44 ]]== {{ ""SSppaaddeess““ ,, ""HHeeaarrttss““ ,, ""DDiiaammoonnddss““ ,, ""CClluubbss““ }} ;; ccoonnsstt cchhaarr **ffaaccee [[ 1133 ]] == {{ ""AAccee““ ,, ""DDeeuuccee““ ,, ""TThhrreeee““ ,, ""FFoouurr"",, ""FFiivvee““ ,, ""SSiixx““ ,, ""SSeevveenn““ ,, ""EEiigghhtt““ ,, ""NNiinnee““ ,, ""TTeenn““ ,, ""JJaacckk““ ,, ""QQuueeeenn““ ,, ""KKiinngg"" }} ;; iinntt ddeecckk [[ 44 ]] [[ 1133 ]] == {{ 00 }} ;; ssrraanndd (( ttiimmee (( 00 )) )) ;; sshhuuffffllee (( ddeecckk )) ;; ddeeaall (( ddeecckk ,, ffaaccee ,, ssuuiitt )) ;;
  • 20. SShhuuffffllee FFuunnccttiioonnss vvooiidd sshhuuffffllee (( iinntt wwDDeecckk [[ ]] [[ 1133 ]] )) {{ iinntt rrooww ,, ccoolluummnn ,, ccaarrdd ;; ffoorr (( ccaarrdd == 11 ;; ccaarrdd <<== 5522 ;; ccaarrdd ++++ )) {{ ddoo {{ rrooww == rraanndd (( )) %% 44 ;; ccoolluummnn == rraanndd (( )) %% 1133 ;; }} wwhhiillee(( wwDDeecckk[[ rrooww ]]|| ccoolluummnn ]] !!== 00 )) ;; wwDDeecckk [[ rrooww ]] [[ ccoolluummnn ]] == ccaarrdd ;; }} }}
  • 21. DDeeaall FFuunnccttiioonn vvooiidd ddeeaall (( ccoonnsstt iinntt wwDDeecckk [[ ]] [[ 1133 ]] ,, ccoonnsstt cchhaarr **wwFFaaccee [[ ]] ,, ccoonnsstt cchhaarr **wwSSuuiitt [[ ]] )) {{ iinntt ccaarrdd ,, rrooww ,, ccoolluummnn ;; ffoorr (( ccaarrdd == 11 ;; ccaarrdd <<== 5522 ;; ccaarrdd ++++ )) {{ ffoorr (( rrooww == 00 ;; rrooww <<== 33 ;; rrooww++++ )) {{ ffoorr (( ccoolluummnn == 00 ;; ccoolluummnn <<== 1122 ;; ccoolluummnn ++++ )) {{ iiff (( wwDDeecckk [[ rrooww ]] [[ ccoolluummnn ]] ==== ccaarrdd )) //// PPrriinntt tthhee ffaaccee aanndd ssuuiitt ooff tthhee ccaarrdd //// bbrreeaakk oouutt ooff llooooppss }} }} }} }}
  • 22. WWhhaatt wwee hhaavvee ddoonnee ttooddaayy  MMuullttii--ddiimmeennssiioonnaall AArrrraayyss  PPooiinntteerrss ttoo PPooiinntteerrss  AArrrraayyss ooff PPooiinntteerrss  CCoommmmaanndd LLiinnee AArrgguummeennttss  CCoommpprreehheennssiivvee EExxaammppllee