Page 77 - DCAP407_DATA_STRUCTURE
P. 77
Data Structure
Here, x is defined as a pointer to a group of one-dimensional array, each having 3 elements in an array.
Initially, x points to the first dimensional array called the first row of matrix which is Row 0. (x+1)
points to the second one-dimensional array which is Row 1. (x+2) points to the third dimensional array
which is Row 2.
So, the starting address of the i Row can be accessed using:
th
x+i
The entire i Row can be accessed using:
th
*(x+i)
The address of the first element in the j Column can be accessed using:
th
*(x+i) + j
The item in the j Column can be accessed using:
th
*(*(x+i)+j)
Thus, by using &x[i][j] or *(x+i)+j address of the i Row and j Column can be obtained and by using
th
th
x[i][j] or *(*(x+i)+j) the item at the i Row and j Column can be obtained.
th
th
A three-dimensional array of float type can be defined as:
float b[10][20][30];
A three-dimensional array using pointers can be defined as:
float (*b)[20][30];
A multidimensional array can be represented in terms of an array of pointers. The definition of a
conventional array is:
data_type array_name[exp1][exp2];
Array of pointers can be used to define two-dimensional array as
data_type *array_name[exp1];
Here, data_type refers to the data type of an array
array_name is the name of the array
exp1 is the maximum number of elements in the row
Here, exp2 is not used while defining array of pointers.
Suppose, a two-dimensional vector is initialized with 3 rows and 3 columns as
int d[3][3] = {
{ 10, 12, 14}
{ 20, 22, 24}
{ 30, 32, 34}
};
70 LOVELY PROFESSIONAL UNIVERSITY