Data Structures Using C, 2e Reema Thareja
Data Structures Using C, 2e Reema Thareja
Data Structures Using C, 2e Reema Thareja
C, 2e
Reema Thareja
Arrays
marks[0] marks[1] marks[2] marks[3] marks[4] marks[5] marks[6] marks[7] marks[8] marks[9]
int i, marks[10];
for(i=0;i<10;i++)
marks[i] = -1;
Assign values to
the elements
99 67 78 56 88 90 34 85
Passing addresses
main() void func(int *num)
{ {
int arr[5] ={1, 2, 3, 4, 5}; printf("%d", *num);
func(&arr[3]); }
}
int *ptr[10];
•The above statement declares an array of 10 pointers where each
of the pointer points to an integer variable. For example, look at the
code given below.
int *ptr[10];
int p=1, q=2, r=3, s=4, t=5;
ptr[0]=&p;
ptr[1]=&q;
Can you tell what will be the output of the following statement?
printf(“\n %d”, *ptr[3]);
First Dimension
as:
data_type array_name[row_size]
[column_size];
Second Dimension
int marks[3][5];
• There are two ways of storing a 2-D array in memory. The first
way is row-major order and the second is column-major order.
• In the row-major order the elements of the first row are stored
before the elements of the second and third rows. That is, the
elements of the array are stored row by row where n elements of
the first row will occupy the first nth locations.
(0,0) (0, 1) (0,2) (0,3) (1,0) (1,1) (1,2) (1,3) (2,0) (2,1) (2,2) (2,3)
(0,0) (1,0) (2,0) (3,0) (0,1) (1,1) (2,1) (3,1) (0,2) (1,2) (2,2) (3,2)
arr[i][j][k]= *(*(*(arr+i)+j)+k)