SlideShare uma empresa Scribd logo
1 de 33
ARRAY
Tejas Patel
Harekrushna Patel
Page 1
Content…
•
•
•
•

What are arrays?
Types of arrays
Single dimensional array
Multi dimensional array

Page 2
What are Arrays?
• Array is a data structure, which provides the facility to
store a collection of data of same type under single
variable name.

• It is a group of consecutive memory locations having same
name and type.

Page 3
Types
• One dimensional
• Multi dimensional

Page 4
Single Dimensional Array
• Element specified by single subscript
• Array declaration is made by specifying the data type, it’s
name and the number of space (size) so that the computer
may reserve the appropriate amount of memory.
Syntax
type array_name [ size ]

Base
type of
array

Name of No. of elements that can be
array
stored: Can be a integer
value without the sign

Page 5
Single dimensional Array Working
When user inputting data in array
i=0
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}

a[0]

a[1]

a[2]

a[3]

a[4]
Page 6
Single dimensional Array Working
When user inputting data in array
i=0
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}

a[0]

a[1]

a[2]

a[3]

a[4]
Page 7
Single dimensional Array Working
When user inputting data in array
i=0
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}

5

a[0]

a[1]

a[2]

a[3]

a[4]
Page 8
Single dimensional Array Working
When user inputting data in array

for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}
i=1

5

a[0]

a[1]

a[2]

a[3]

a[4]
Page 9
Single dimensional Array Working
When user inputting data in array
i=1
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}

5

a[0]

a[1]

a[2]

a[3]

a[4]
Page 10
Single dimensional Array Working
When user inputting data in array
i=1
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}

5

10

a[0]

a[1]

a[2]

a[3]

a[4]
Page 11
Single dimensional Array Working
When user inputting data in array

for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}
i=2

5

10

a[0]

a[1]

a[2]

a[3]

a[4]
Page 12
Single dimensional Array Working
When user inputting data in array
i=2
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}

5

10

a[0]

a[1]

a[2]

a[3]

a[4]
Page 13
Single dimensional Array Working
When user inputting data in array
i=2
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}

5

10

15

a[0]

a[1]

a[2]

a[3]

a[4]
Page 14
Single dimensional Array Working
When user inputting data in array

for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}
i=3

5

10

15

a[0]

a[1]

a[2]

a[3]

a[4]
Page 15
Single dimensional Array Working
When user inputting data in array
i=3
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}

5

10

15

a[0]

a[1]

a[2]

a[3]

a[4]
Page 16
Single dimensional Array Working
When user inputting data in array
i=3
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}

5

10

15

a[0]

a[1]

a[2]

20

a[3]

a[4]
Page 17
Single dimensional Array Working
When user inputting data in array

for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}
i=4

5

10

15

a[0]

a[1]

a[2]

20

a[3]

a[4]
Page 18
Single dimensional Array Working
When user inputting data in array
i=4
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}

5

10

15

a[0]

a[1]

a[2]

20

a[3]

a[4]
Page 19
Single dimensional Array Working
When user inputting data in array
i=4
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}

5

10

15

a[0]

a[1]

a[2]

20

25

a[3]

a[4]
Page 20
Single dimensional Array Working
When user inputting data in array

for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}
i=5

5

10

15

a[0]

a[1]

a[2]

20

25

a[3]

a[4]
Page 21
Single dimensional Array Working
When user inputting data in array

i=5
i=5
for(i=0;i<5;i++)
{
scanf(“%d”,&a[i]);
}

5

10

15

a[0]

a[1]

a[2]

20

25

a[3]

a[4]
Page 22
Single dimensional Array Working
When user inputting data in array

i=5
i=5
for(i=0; i<5 ;i++)
{
scanf(“%d”,&a[i]);
}

5

10

15

a[0]

a[1]

a[2]

20

25

a[3]

a[4]
Page 23
Single dimensional Array Working
When user inputting data in array

i=5
i=5

Here, i=5 & condition is i<5 so
condition not satisfied

for(i=0; i<5 ;i++)
{
scanf(“%d”,&a[i]);
}

5

10

15

a[0]

a[1]

a[2]

20

25

a[3]

a[4]
Page 24
Two Dimensional Array
• A two dimensional array is a collection of elements placed in
rows and columns.
• The syntax used to declare two dimensional array includes two
subscripts, of which one specifies the number of rows and the
other specifies the number of columns.
• These two subscripts are used to reference an element in an
array.

Page 25
Syntax
<data type> <array name> [row size]

[column size];

<data type> <array name> [row size] [column size]={values};

Page 26
Example
int num[3][2]={4,3,5,6,8,9};
or
int num[3][2]={{4,3},{5,6},{8,9}};
values
column size
row size
array name
data type

Page 27
Representation of the 2-D Array
Rows

columns

0th column

1st column

0th row
1st row
2nd row

Page 28
Multi dimensional Arrays
• An array haves 2 or more subscripts, that type of array is called
multi dimensional array.
• The 3 –D array is called as multidimensional array this can be
thought of as an array of two dimensional arrays.
• Each element of a 3-D array is accessed using subscripts, one
for each dimension.

Page 29
Multiple Dimensional Array
• Tables with rows and columns (m by n array)
• Like matrices: specify row, then column
Column 0

Column 1

Column 2

Column 3

Row 0

a[ 0 ][ 0 ]

a[ 0 ][ 1 ]

a[ 0 ][ 2 ]

a[ 0 ][ 3 ]

Row 1

a[ 1 ][ 0 ]

a[ 1 ][ 1 ]

a[ 1 ][ 2 ]

a[ 1 ][ 3 ]

a[ 2 ][ 0 ]

a[ 2 ][ 1 ]

a[ 2 ][ 2 ]

a[ 2 ][ 3 ]

Row 2

Column subscript
Array name
Row subscript

Page 30
Initialization
• int b[2][2] = {{1,2},{3,4}};
• Initializers grouped by row in braces
• If not enough, unspecified elements set to zero
int b[2][2] = {{1},{3,4}};

Page 31
Important
• The most important thing to remember about array
allocation is that the elements of the array are indexed
starting at 0, not 1. If the number of cells in an array is
N, then the indexes run from 0 to N-1.

Page 32
Array

Mais conteúdo relacionado

Mais procurados

Presentation on array
Presentation on array Presentation on array
Presentation on array
topu93
 

Mais procurados (20)

Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Python list
Python listPython list
Python list
 
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
stack & queue
stack & queuestack & queue
stack & queue
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
 
Stack
StackStack
Stack
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Stack project
Stack projectStack project
Stack project
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 

Destaque

Task 2 working to a brief pro-forma
Task 2   working to a brief pro-formaTask 2   working to a brief pro-forma
Task 2 working to a brief pro-forma
harisshaikhPBM
 
ایتالیا و استقرار مجدد حاکمیت قانون در افغانستان
ایتالیا و استقرار مجدد حاکمیت قانون در افغانستانایتالیا و استقرار مجدد حاکمیت قانون در افغانستان
ایتالیا و استقرار مجدد حاکمیت قانون در افغانستان
IDCOAFGHANISTAN
 
Evaluation Question 3
Evaluation Question 3Evaluation Question 3
Evaluation Question 3
Jacknight
 
تحقیق پیرامون محاکم قانونی افغانستان
تحقیق پیرامون محاکم قانونی افغانستانتحقیق پیرامون محاکم قانونی افغانستان
تحقیق پیرامون محاکم قانونی افغانستان
IDCOAFGHANISTAN
 
Gogoeta egiteko lekua ibon
Gogoeta egiteko lekua ibonGogoeta egiteko lekua ibon
Gogoeta egiteko lekua ibon
ibonlaka
 
Praveen datla business_development_manager_15_years_cv
Praveen datla business_development_manager_15_years_cvPraveen datla business_development_manager_15_years_cv
Praveen datla business_development_manager_15_years_cv
Praveen Datla
 

Destaque (20)

Global environmental issues
Global environmental issuesGlobal environmental issues
Global environmental issues
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP Arrays
 
Task 8
Task 8Task 8
Task 8
 
2 tinggal 2 tamu
2 tinggal 2 tamu2 tinggal 2 tamu
2 tinggal 2 tamu
 
Tqm presentation
Tqm presentationTqm presentation
Tqm presentation
 
JAVA J2EE Training in Coimbatore - Fundamentals of Java J2EE
JAVA J2EE Training in Coimbatore - Fundamentals of Java J2EE JAVA J2EE Training in Coimbatore - Fundamentals of Java J2EE
JAVA J2EE Training in Coimbatore - Fundamentals of Java J2EE
 
Human Body - Muscular System
Human Body - Muscular SystemHuman Body - Muscular System
Human Body - Muscular System
 
Tic
TicTic
Tic
 
Task 2 working to a brief pro-forma
Task 2   working to a brief pro-formaTask 2   working to a brief pro-forma
Task 2 working to a brief pro-forma
 
ایتالیا و استقرار مجدد حاکمیت قانون در افغانستان
ایتالیا و استقرار مجدد حاکمیت قانون در افغانستانایتالیا و استقرار مجدد حاکمیت قانون در افغانستان
ایتالیا و استقرار مجدد حاکمیت قانون در افغانستان
 
Evaluation Question 3
Evaluation Question 3Evaluation Question 3
Evaluation Question 3
 
تحقیق پیرامون محاکم قانونی افغانستان
تحقیق پیرامون محاکم قانونی افغانستانتحقیق پیرامون محاکم قانونی افغانستان
تحقیق پیرامون محاکم قانونی افغانستان
 
Transcript+Cer
Transcript+CerTranscript+Cer
Transcript+Cer
 
CXPA Finland Ajankohtaista - Certified Customer Experience Professional (CCXP...
CXPA Finland Ajankohtaista - Certified Customer Experience Professional (CCXP...CXPA Finland Ajankohtaista - Certified Customer Experience Professional (CCXP...
CXPA Finland Ajankohtaista - Certified Customer Experience Professional (CCXP...
 
Egg Program - End 3rd year -
Egg Program - End 3rd year - Egg Program - End 3rd year -
Egg Program - End 3rd year -
 
Slide hm 2015 indo
Slide hm 2015 indoSlide hm 2015 indo
Slide hm 2015 indo
 
EECS 497 Intro
EECS 497 IntroEECS 497 Intro
EECS 497 Intro
 
Gogoeta egiteko lekua ibon
Gogoeta egiteko lekua ibonGogoeta egiteko lekua ibon
Gogoeta egiteko lekua ibon
 
Praveen datla business_development_manager_15_years_cv
Praveen datla business_development_manager_15_years_cvPraveen datla business_development_manager_15_years_cv
Praveen datla business_development_manager_15_years_cv
 
Reformasi pemda (riview)
Reformasi pemda (riview)Reformasi pemda (riview)
Reformasi pemda (riview)
 

Semelhante a Array

data structure unit -1_170434dd7400.pptx
data structure unit -1_170434dd7400.pptxdata structure unit -1_170434dd7400.pptx
data structure unit -1_170434dd7400.pptx
coc7987515756
 
BHARGAVIARRAY.PPT.pptx
BHARGAVIARRAY.PPT.pptxBHARGAVIARRAY.PPT.pptx
BHARGAVIARRAY.PPT.pptx
Sasideepa
 

Semelhante a Array (20)

Array
ArrayArray
Array
 
Arrays
ArraysArrays
Arrays
 
Array
ArrayArray
Array
 
Array 2 hina
Array 2 hina Array 2 hina
Array 2 hina
 
Arrays
ArraysArrays
Arrays
 
Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
data structure unit -1_170434dd7400.pptx
data structure unit -1_170434dd7400.pptxdata structure unit -1_170434dd7400.pptx
data structure unit -1_170434dd7400.pptx
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
BHARGAVIARRAY.PPT.pptx
BHARGAVIARRAY.PPT.pptxBHARGAVIARRAY.PPT.pptx
BHARGAVIARRAY.PPT.pptx
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
Python array
Python arrayPython array
Python array
 
R training3
R training3R training3
R training3
 
Arrays
ArraysArrays
Arrays
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Array-part1
Array-part1Array-part1
Array-part1
 

Último

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
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Último (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
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.
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
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
 
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...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

Array

  • 2. Content… • • • • What are arrays? Types of arrays Single dimensional array Multi dimensional array Page 2
  • 3. What are Arrays? • Array is a data structure, which provides the facility to store a collection of data of same type under single variable name. • It is a group of consecutive memory locations having same name and type. Page 3
  • 4. Types • One dimensional • Multi dimensional Page 4
  • 5. Single Dimensional Array • Element specified by single subscript • Array declaration is made by specifying the data type, it’s name and the number of space (size) so that the computer may reserve the appropriate amount of memory. Syntax type array_name [ size ] Base type of array Name of No. of elements that can be array stored: Can be a integer value without the sign Page 5
  • 6. Single dimensional Array Working When user inputting data in array i=0 for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } a[0] a[1] a[2] a[3] a[4] Page 6
  • 7. Single dimensional Array Working When user inputting data in array i=0 for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } a[0] a[1] a[2] a[3] a[4] Page 7
  • 8. Single dimensional Array Working When user inputting data in array i=0 for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } 5 a[0] a[1] a[2] a[3] a[4] Page 8
  • 9. Single dimensional Array Working When user inputting data in array for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } i=1 5 a[0] a[1] a[2] a[3] a[4] Page 9
  • 10. Single dimensional Array Working When user inputting data in array i=1 for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } 5 a[0] a[1] a[2] a[3] a[4] Page 10
  • 11. Single dimensional Array Working When user inputting data in array i=1 for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } 5 10 a[0] a[1] a[2] a[3] a[4] Page 11
  • 12. Single dimensional Array Working When user inputting data in array for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } i=2 5 10 a[0] a[1] a[2] a[3] a[4] Page 12
  • 13. Single dimensional Array Working When user inputting data in array i=2 for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } 5 10 a[0] a[1] a[2] a[3] a[4] Page 13
  • 14. Single dimensional Array Working When user inputting data in array i=2 for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } 5 10 15 a[0] a[1] a[2] a[3] a[4] Page 14
  • 15. Single dimensional Array Working When user inputting data in array for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } i=3 5 10 15 a[0] a[1] a[2] a[3] a[4] Page 15
  • 16. Single dimensional Array Working When user inputting data in array i=3 for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } 5 10 15 a[0] a[1] a[2] a[3] a[4] Page 16
  • 17. Single dimensional Array Working When user inputting data in array i=3 for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } 5 10 15 a[0] a[1] a[2] 20 a[3] a[4] Page 17
  • 18. Single dimensional Array Working When user inputting data in array for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } i=4 5 10 15 a[0] a[1] a[2] 20 a[3] a[4] Page 18
  • 19. Single dimensional Array Working When user inputting data in array i=4 for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } 5 10 15 a[0] a[1] a[2] 20 a[3] a[4] Page 19
  • 20. Single dimensional Array Working When user inputting data in array i=4 for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } 5 10 15 a[0] a[1] a[2] 20 25 a[3] a[4] Page 20
  • 21. Single dimensional Array Working When user inputting data in array for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } i=5 5 10 15 a[0] a[1] a[2] 20 25 a[3] a[4] Page 21
  • 22. Single dimensional Array Working When user inputting data in array i=5 i=5 for(i=0;i<5;i++) { scanf(“%d”,&a[i]); } 5 10 15 a[0] a[1] a[2] 20 25 a[3] a[4] Page 22
  • 23. Single dimensional Array Working When user inputting data in array i=5 i=5 for(i=0; i<5 ;i++) { scanf(“%d”,&a[i]); } 5 10 15 a[0] a[1] a[2] 20 25 a[3] a[4] Page 23
  • 24. Single dimensional Array Working When user inputting data in array i=5 i=5 Here, i=5 & condition is i<5 so condition not satisfied for(i=0; i<5 ;i++) { scanf(“%d”,&a[i]); } 5 10 15 a[0] a[1] a[2] 20 25 a[3] a[4] Page 24
  • 25. Two Dimensional Array • A two dimensional array is a collection of elements placed in rows and columns. • The syntax used to declare two dimensional array includes two subscripts, of which one specifies the number of rows and the other specifies the number of columns. • These two subscripts are used to reference an element in an array. Page 25
  • 26. Syntax <data type> <array name> [row size] [column size]; <data type> <array name> [row size] [column size]={values}; Page 26
  • 28. Representation of the 2-D Array Rows columns 0th column 1st column 0th row 1st row 2nd row Page 28
  • 29. Multi dimensional Arrays • An array haves 2 or more subscripts, that type of array is called multi dimensional array. • The 3 –D array is called as multidimensional array this can be thought of as an array of two dimensional arrays. • Each element of a 3-D array is accessed using subscripts, one for each dimension. Page 29
  • 30. Multiple Dimensional Array • Tables with rows and columns (m by n array) • Like matrices: specify row, then column Column 0 Column 1 Column 2 Column 3 Row 0 a[ 0 ][ 0 ] a[ 0 ][ 1 ] a[ 0 ][ 2 ] a[ 0 ][ 3 ] Row 1 a[ 1 ][ 0 ] a[ 1 ][ 1 ] a[ 1 ][ 2 ] a[ 1 ][ 3 ] a[ 2 ][ 0 ] a[ 2 ][ 1 ] a[ 2 ][ 2 ] a[ 2 ][ 3 ] Row 2 Column subscript Array name Row subscript Page 30
  • 31. Initialization • int b[2][2] = {{1,2},{3,4}}; • Initializers grouped by row in braces • If not enough, unspecified elements set to zero int b[2][2] = {{1},{3,4}}; Page 31
  • 32. Important • The most important thing to remember about array allocation is that the elements of the array are indexed starting at 0, not 1. If the number of cells in an array is N, then the indexes run from 0 to N-1. Page 32