krsnabansi
Programmer
Hello,
Of late, I have been reading about using pointer notation with multidimensional arrays. I have the following doubts:
1. It is easy to undertand the memory allocation pattern in the case of one-dimensional array. For example,
double values[10];
double* pvalues = values;
in the above expression, values is the address of the first element of the array.
But, I am pretty confused about the memory allocation pattern in the case of multidimensional arrrays. For example,
double values[j];
Now, if I need to declare a pointer to the array, I can't do it as
double* pvalues = values:/*wrong!!!*/
instead I should declare it as
double *(pvalues)[j] = values;
Could anyone explain the logic behind this?
2. If I have to access the element in a one-dimensional array using pointer notation, I can do as follows:
(pvalues + i);/*assuming pvalues = values*/
But to achieve the same in the case of a multi-dimensional array, I have to write the following expression:
(*(values + i) + j)
But in both the cases, values refers to the address of the first element.
Could anyone explain?
thanks
KB
Of late, I have been reading about using pointer notation with multidimensional arrays. I have the following doubts:
1. It is easy to undertand the memory allocation pattern in the case of one-dimensional array. For example,
double values[10];
double* pvalues = values;
in the above expression, values is the address of the first element of the array.
But, I am pretty confused about the memory allocation pattern in the case of multidimensional arrrays. For example,
double values[j];
Now, if I need to declare a pointer to the array, I can't do it as
double* pvalues = values:/*wrong!!!*/
instead I should declare it as
double *(pvalues)[j] = values;
Could anyone explain the logic behind this?
2. If I have to access the element in a one-dimensional array using pointer notation, I can do as follows:
(pvalues + i);/*assuming pvalues = values*/
But to achieve the same in the case of a multi-dimensional array, I have to write the following expression:
(*(values + i) + j)
But in both the cases, values refers to the address of the first element.
Could anyone explain?
thanks
KB