Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

# Saving this for later?

### Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Standard text messaging rates apply

# Array

288
views

Published on

Basic Fundamental Of Array

Basic Fundamental Of Array

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
288
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
21
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. ARRAY Tejas Patel Harekrushna Patel Page 1
• 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
• 27. 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
• 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