Your problem is that *x[i]=i;
means *(x[i])=i;
, but what you want is (*x)[i]=i;
.
This happens because both x[i]
and *x
are pointers to int
, so the compiler can't catch the error.
(*x[i]
is equivalent to x[i][0]
, while (*x)[i]
is equivalent to x[0][i]
.)
To avoid the issue, and the parentheses, you can rewrite like this:
void call_fc_(int **x, int s)
{
int i;
int *y = (int *) malloc(sizeof(int)*s);
for(i = 0; i < 100 && i < s; i++)
{
cout << i << endl;
y[i]=i;
}
*x = y;
}
I added a test for i < s
in order to avoid writing outside the array.