SlideShare une entreprise Scribd logo
1  sur  24
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 1
 Introduction to the ARRAY
 Classification
 Array Declaration
 Array Initialization
 Array with FOR Loop
 Upper and lower limit of Array
 Advantages
 Disadvantages
 Conclusion
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 2
 An Array is a group of memory location s
having same data type
 Data type specify the type of data it stores
 A group of CONTINOUS memory locations
Example: Int A[0][1][2][3][4]
 Store JUST single variable
 C++ store list values in it
 Arrange in Rows/ Columns
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 3
To refer a particular location its Name and
its “SUBSCRIPT “is specifies
WHAT IS A „SUBSCRIPT‟?
The number contained within Square bracket
It MUST be an integer or expression
If its an integer expression then it is
evaluated to describe the subscript
EXAMPLE:
c[a+b] +=2; if a=5, and b=6
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 4
In some languages (e.g. COBOL) arrays are
called “Tables”.
An individual value in an array is called an
“Element”
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 5
There are divided into following types;
1. One Dimensional Arrays:
A[0][1][2][3][4][5][6]………………[n]
2. Two Dimensional Arrays:
3. Multi Dimensional Arrays:
3D, 4D etc
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 6
A[0][0] A[0][1] A[0][2] A[0][3] A[0][4]
A[1][0] A[1][1] A[1][2] A[1][3] A[1][4]
A[2][0] A[2][1] A[2][2] A[2][3] A[2][4]
We Explore The Following Things in this Section:
•Arrays Declaration
•Arrays Initialization
•With FOR Loop
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 7
As just in few steps…
Lets have an example of OVERS in a cricket
match, its 6 per over
We declared it something like that…
Int balls[5]
Subscript/index
Array_name
OR….
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 8
Its still the same!!!
Int balls= {1,2,3,4,5,6}
More Examplex:
Char city= {L,A,H,O,R,E}
FLOAT NUM={1.2, 1.3, 1.4 ,1.5 }
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 9
It can be intialized as they declared
Do not need to declared the subscript if initial
values are defined
What's the initial values we are talking about..
Int k[]= {12,13,14,15}
WE HAVENT SEPCIFY THE INDEX-ANOTHER
NAME AND STIL IT WORKS
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 10
Because array automatically generate the
space for it
JUST FOR UNDERSTANDING!!!
Int k [5]= {12,13,14,15}
With index it something look like this…..
C++ does not flag out any error if index go
out of the bound…
HOW?????
Char k[7]={A,R,R,A,Y}
Even the memory remains empty still it does
not cerate any error…
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 11
Almost always needed to steep through the ARRAY
The loop is used is “FOR-LOOP”
Can not do manipulation easily then
BUT WHY?????
 Loops are use to REPEATATION
so as in the case of array we MUXT declared the
index of ≥0 ; for
 C++ to pick up the required index it uses the loop.
But just not used in some fewer cases
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 12
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 13
• We „r going to explore the following contents in
this:
1. Introduction to 2D-Array
2. 2D Array with nested FOR loop
3. Upper and lower limit of array
4. Advantages
5. Disadvantages
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 14
It has rows and columns…… just like a
TABLE
Also known as MATRIX
EXAMPLE:
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 15
A[0][0] A[0][1] A[0][2] A[0][3] A[0][4]
A[1][0] A[1][1] A[1][2] A[1][3] A[1][4]
A[2][0] A[2][1] A[2][2] A[2][3] A[2][4]
HOW TO DECLARE 2D-ARRAY??? This way
Int temps[2][2]
Row * column = 2*2: holding 4 integers
NOW HOW to INITIALIZE IT??????
JUST simple!!!
Int temps[2][2]={{12,14} , {21,41}}:
Value of each is held in {}
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 16
In GENERAL:
ARRAY_NAME[row][column]={row}{column}
[SUBSCRIPT]
Both parts of an index MUST be an integer
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 17
Nested FOR loops to step through 2D-Array
USUALL FORMAT:
FOR EACH ROW, FOR EACH COLUMN
Do something to array[row][column]
EXAMPLE:
Int team[2][3];
For(int row=0;orw<2;;row++){
For(int row=0;orw<2;;row++){
Team[row][column]=8: }}
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 18
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 19
Mid versions of BASIC allowed any starting
and ending value. So we could have arrays like
the following:
EXAMPLE:
int years (1998 to 2008)
int tide. level(-5 to +5)
 Many “modern” languages do not allow this
freedom with declaring arrays
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 20
* simple and easy to create
Any element of an array can be accessed time
by its index
Random access
Constant size
arrays with arbitrary size (dynamically
allocated array)
array will always hold similar kind of information
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 21
We cant change the size of array during run
time
Constant size WITH Constant data-type
Array data structure is not completely
dynamic.
Insertion and deletion of an element in the
array requires to shift the locations
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 22
The Prospective of what we have presented
now is to JUST enhance the ability of
ourselves;
Its up to US how we cater down al this in
our practical LIFE…
We have to crave what is perfect from
INSIDE!!!!
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 23
1. C How to program, 4th edition by DEITEL
2. WWW.gavilian.edu/adnvantages/histroy/a
rrays.htm
3. WWW.agolist.net/data-strcutures/arrays
2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 24

Contenu connexe

En vedette

協力隊フィールド調査団 セネガル隊・キックオフ資料(2014年4月)
協力隊フィールド調査団 セネガル隊・キックオフ資料(2014年4月)協力隊フィールド調査団 セネガル隊・キックオフ資料(2014年4月)
協力隊フィールド調査団 セネガル隊・キックオフ資料(2014年4月)Yo Kotsuji
 
協力隊市場調査団実行マニュアル
協力隊市場調査団実行マニュアル協力隊市場調査団実行マニュアル
協力隊市場調査団実行マニュアルYo Kotsuji
 
Rs satellites catelogue 2012
Rs satellites catelogue 2012Rs satellites catelogue 2012
Rs satellites catelogue 2012Atiqa Khan
 
Koppen classification 2011
Koppen classification 2011Koppen classification 2011
Koppen classification 2011Atiqa Khan
 
協力隊フィールド調査団マニュアル(2014年7月版)
協力隊フィールド調査団マニュアル(2014年7月版)協力隊フィールド調査団マニュアル(2014年7月版)
協力隊フィールド調査団マニュアル(2014年7月版)Yo Kotsuji
 
Interpolation 2013
Interpolation 2013Interpolation 2013
Interpolation 2013Atiqa Khan
 
Building Enclosures For the Future - Building Tomorrows Buildings Today
Building Enclosures For the Future - Building Tomorrows Buildings TodayBuilding Enclosures For the Future - Building Tomorrows Buildings Today
Building Enclosures For the Future - Building Tomorrows Buildings TodayGraham Finch
 
La oración compuesta.pptx ultimo
La oración compuesta.pptx ultimoLa oración compuesta.pptx ultimo
La oración compuesta.pptx ultimoOoda
 

En vedette (13)

Moons 2009
Moons 2009Moons 2009
Moons 2009
 
Pca 2012
Pca 2012Pca 2012
Pca 2012
 
Moons 2009
Moons 2009Moons 2009
Moons 2009
 
協力隊フィールド調査団 セネガル隊・キックオフ資料(2014年4月)
協力隊フィールド調査団 セネガル隊・キックオフ資料(2014年4月)協力隊フィールド調査団 セネガル隊・キックオフ資料(2014年4月)
協力隊フィールド調査団 セネガル隊・キックオフ資料(2014年4月)
 
協力隊市場調査団実行マニュアル
協力隊市場調査団実行マニュアル協力隊市場調査団実行マニュアル
協力隊市場調査団実行マニュアル
 
Rs satellites catelogue 2012
Rs satellites catelogue 2012Rs satellites catelogue 2012
Rs satellites catelogue 2012
 
Koppen classification 2011
Koppen classification 2011Koppen classification 2011
Koppen classification 2011
 
Pca 2012
Pca 2012Pca 2012
Pca 2012
 
協力隊フィールド調査団マニュアル(2014年7月版)
協力隊フィールド調査団マニュアル(2014年7月版)協力隊フィールド調査団マニュアル(2014年7月版)
協力隊フィールド調査団マニュアル(2014年7月版)
 
Clouds 2011
Clouds 2011Clouds 2011
Clouds 2011
 
Interpolation 2013
Interpolation 2013Interpolation 2013
Interpolation 2013
 
Building Enclosures For the Future - Building Tomorrows Buildings Today
Building Enclosures For the Future - Building Tomorrows Buildings TodayBuilding Enclosures For the Future - Building Tomorrows Buildings Today
Building Enclosures For the Future - Building Tomorrows Buildings Today
 
La oración compuesta.pptx ultimo
La oración compuesta.pptx ultimoLa oración compuesta.pptx ultimo
La oración compuesta.pptx ultimo
 

Dernier

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 

Dernier (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

Array 2011

  • 1. 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 1
  • 2.  Introduction to the ARRAY  Classification  Array Declaration  Array Initialization  Array with FOR Loop  Upper and lower limit of Array  Advantages  Disadvantages  Conclusion 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 2
  • 3.  An Array is a group of memory location s having same data type  Data type specify the type of data it stores  A group of CONTINOUS memory locations Example: Int A[0][1][2][3][4]  Store JUST single variable  C++ store list values in it  Arrange in Rows/ Columns 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 3
  • 4. To refer a particular location its Name and its “SUBSCRIPT “is specifies WHAT IS A „SUBSCRIPT‟? The number contained within Square bracket It MUST be an integer or expression If its an integer expression then it is evaluated to describe the subscript EXAMPLE: c[a+b] +=2; if a=5, and b=6 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 4
  • 5. In some languages (e.g. COBOL) arrays are called “Tables”. An individual value in an array is called an “Element” 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 5
  • 6. There are divided into following types; 1. One Dimensional Arrays: A[0][1][2][3][4][5][6]………………[n] 2. Two Dimensional Arrays: 3. Multi Dimensional Arrays: 3D, 4D etc 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 6 A[0][0] A[0][1] A[0][2] A[0][3] A[0][4] A[1][0] A[1][1] A[1][2] A[1][3] A[1][4] A[2][0] A[2][1] A[2][2] A[2][3] A[2][4]
  • 7. We Explore The Following Things in this Section: •Arrays Declaration •Arrays Initialization •With FOR Loop 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 7
  • 8. As just in few steps… Lets have an example of OVERS in a cricket match, its 6 per over We declared it something like that… Int balls[5] Subscript/index Array_name OR…. 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 8
  • 9. Its still the same!!! Int balls= {1,2,3,4,5,6} More Examplex: Char city= {L,A,H,O,R,E} FLOAT NUM={1.2, 1.3, 1.4 ,1.5 } 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 9
  • 10. It can be intialized as they declared Do not need to declared the subscript if initial values are defined What's the initial values we are talking about.. Int k[]= {12,13,14,15} WE HAVENT SEPCIFY THE INDEX-ANOTHER NAME AND STIL IT WORKS 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 10
  • 11. Because array automatically generate the space for it JUST FOR UNDERSTANDING!!! Int k [5]= {12,13,14,15} With index it something look like this….. C++ does not flag out any error if index go out of the bound… HOW????? Char k[7]={A,R,R,A,Y} Even the memory remains empty still it does not cerate any error… 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 11
  • 12. Almost always needed to steep through the ARRAY The loop is used is “FOR-LOOP” Can not do manipulation easily then BUT WHY?????  Loops are use to REPEATATION so as in the case of array we MUXT declared the index of ≥0 ; for  C++ to pick up the required index it uses the loop. But just not used in some fewer cases 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 12
  • 13. 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 13
  • 14. • We „r going to explore the following contents in this: 1. Introduction to 2D-Array 2. 2D Array with nested FOR loop 3. Upper and lower limit of array 4. Advantages 5. Disadvantages 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 14
  • 15. It has rows and columns…… just like a TABLE Also known as MATRIX EXAMPLE: 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 15 A[0][0] A[0][1] A[0][2] A[0][3] A[0][4] A[1][0] A[1][1] A[1][2] A[1][3] A[1][4] A[2][0] A[2][1] A[2][2] A[2][3] A[2][4]
  • 16. HOW TO DECLARE 2D-ARRAY??? This way Int temps[2][2] Row * column = 2*2: holding 4 integers NOW HOW to INITIALIZE IT?????? JUST simple!!! Int temps[2][2]={{12,14} , {21,41}}: Value of each is held in {} 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 16
  • 17. In GENERAL: ARRAY_NAME[row][column]={row}{column} [SUBSCRIPT] Both parts of an index MUST be an integer 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 17
  • 18. Nested FOR loops to step through 2D-Array USUALL FORMAT: FOR EACH ROW, FOR EACH COLUMN Do something to array[row][column] EXAMPLE: Int team[2][3]; For(int row=0;orw<2;;row++){ For(int row=0;orw<2;;row++){ Team[row][column]=8: }} 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 18
  • 19. 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 19
  • 20. Mid versions of BASIC allowed any starting and ending value. So we could have arrays like the following: EXAMPLE: int years (1998 to 2008) int tide. level(-5 to +5)  Many “modern” languages do not allow this freedom with declaring arrays 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 20
  • 21. * simple and easy to create Any element of an array can be accessed time by its index Random access Constant size arrays with arbitrary size (dynamically allocated array) array will always hold similar kind of information 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 21
  • 22. We cant change the size of array during run time Constant size WITH Constant data-type Array data structure is not completely dynamic. Insertion and deletion of an element in the array requires to shift the locations 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 22
  • 23. The Prospective of what we have presented now is to JUST enhance the ability of ourselves; Its up to US how we cater down al this in our practical LIFE… We have to crave what is perfect from INSIDE!!!! 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 23
  • 24. 1. C How to program, 4th edition by DEITEL 2. WWW.gavilian.edu/adnvantages/histroy/a rrays.htm 3. WWW.agolist.net/data-strcutures/arrays 2011 Topic: ARRAY by Atiqa, Rafia ; Rbiya, Rabia 24