0

Here is my current attempt however when I try to assign a double to one element I am told that the "subscripted value is neither array nor pointer nor vector". Can anyone point me in the right direction (pun intended).

int i;
double x[2];
for(i=0;i<2;i++){
double *x[i];
x[i] = (double*) malloc(10000*sizeof(double));
}

2 Answers2

2

Make a static array of pointers:

int i;
double *x[2];
for(i=0;i<2;i++){
    x[i] = malloc(10000*sizeof(double));
}

And proceed as you are (without casting the result of malloc).

Community
  • 1
  • 1
Eugene Sh.
  • 17,802
  • 8
  • 40
  • 61
0

Write the following way

int i;
double *x[2];
for(i=0;i<2;i++){
    x[i] = (double*) malloc(10000*sizeof(double));
}

Or you could even write provided that the array itself has automatic storage duration.

double *x[2] = { malloc(10000*sizeof(double)), malloc(10000*sizeof(double)) };
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335