1

I am using C. I have a double array like this:

double arr[3]={1,2,3};

Next, I assumed that a

double[]

is just like

double *,

and thus I created this pointer variable:

double ** ppdArr = &arr; /* indirection */

I planned to dereference it later and access the items in the original array as follows:

double* pdArr = *ppdArr; /* dereference */
double value = pdArr[0]; /* access violation, because pdArr is NULL */

Why? When using arrays and pointers interchangeably, what is the difference between static vs. dynamic allocation? Or are there other reasons for this error? For example, the following works (as expected):

double *arr2 = ... /*allocated through malloc()*/
double ** ppdArr2 = &arr2; /* indirection */
double *pdArr2 = *ppdArr2; /* dereference */
double value2 = pdArr2[0]; /* works */

0 Answers0