Upcoming SlideShare
×

# Lecture17 arrays.ppt

15,178 views

Published on

arrays in c

Published in: Technology, Education
5 Likes
Statistics
Notes
• Full Name
Comment goes here.

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

Views
Total views
15,178
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
852
0
Likes
5
Embeds 0
No embeds

No notes for slide

### Lecture17 arrays.ppt

1. 1. Prakash KhaireLecturer, B V Patel Institute of BMC & ITARRAYS
2. 2. Arrays●It is derived data type●Arrays are collection of data that belong tosame data type●Arrays are collection of homogeneous data●Array elements can be accessed by its positionin the array called as index●Values in an array are identified using arrayname with subscripts●Also known as subscripted variable●It is fixed-size collection of elements
3. 3. ● Following are types of array●One-dimensional Array●Two-dimensional Array●Multi-dimensional Array
4. 4. One-dimensional Array●A collections of variables are given one variable nameusing only one subscript and such a variable is called asingle-subscripted variable or one dimensional array●Syntax data_type ArrayName[size]; data_type : is a valid data type like int, float or char Arrayname : is a valid identifier size : maximum number of elements that can be stored in array
5. 5. ArraysArray index starts with zeroThe last index in an array is num – 1 wherenum is the no of elements in a arrayint a[9] is an array that stores 9 integers index 0 1 2 3 4 5 6 7 8 elementsMemory address 100 102 104 106 108 110 112 114 116
6. 6. Initilization of Array●After declaring the array, all the elements ofarray must be initialized other wise they willcontain garbage value●At compile time●At run time data_type ArrayName[size] = {list of values}int marks[5] = {55, 63,67,78,59};
7. 7. Each value is treated as an element of the arrayand is stored in the memory as follows marks 55 0 63 1 67 2 78 3 59 4
8. 8. ●float marks[5]={45.5,65.0,67.5.77.0,79 .0};●char name[8]={‘P’,’r’,’a’, ’k’, ’a’, ’s’, ’h’, ’0’};●int marks[] = {63,68,57,69,77};●char name[] = “Prakash”;
9. 9. int marks[5]={67,66};● 67 0 66 1 4646 2 8978 3 -545 4
10. 10. Two Dimensional Array●To store following data of 4 students 201 202 203 204 205 09BCA07 45 42 41 56 46 09BCA14 46 55 70 49 56 09BCA45 65 61 68 42 56 09BCA115 46 38 39 45 42
11. 11. Two Dimensional Array ● StudentDetailsIJ ● Where, StudentDetails represents a matrix I represents no. of rows J represents no. of columns It is collection of rows and columns
12. 12. Two Dimensional Array ● Declaration of 2D array type array_name[row_size][column_size]; column0 column1 column2 column3 column4 Row0 0,0 0,1 0,2 0,3 0,4 Row1 1,0 1,1 1,2 1,3 1,4 Row2 2,0 2,1 2,2 2,3 2,4 Row3 3,0 3,1 3,2 3,3 3,4
13. 13. Storage Representation● Similar to 1D Array, 2D array are also stored in contiguous memory in increasing memory locations.0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2990 992 994 996 998 1000 1002 1004 1006
14. 14. Initilization● int mat[3][3] = { 1,3,2,4,7,6,5,8,9};● int mat[3][3] = { {1,3,2}, {4,7,6}, {5,8,9} };
15. 15. ● int mat[ ][3]={ {1,3,2}, {4,7,6}, {5,8,9} };
16. 16. int mat[3][3] = { {0}, {0}, {0} };● int mat[3][3] = { {1}, {7,6}, {5} }; int mat[3][3] = { {0}, {0}, {0} };
17. 17. ● int mat[3][3] = { 0,0,0};