I am trying to understand how dynamic memory works in C. Suppose I need to allocate memory for some pointer using another function. Is it possible? I tried in the program below, but it keeps crashing in Windows.
void foo(int** x){
*x=(int *)malloc(10*sizeof(int));
int i;
for(i=0; i<10; i++){
*x[i] = 0;
}
}
int main(int argc, char* argv[]){
int *x;
int i;
foo(&x);
for(i=0; i<10; i++){
printf("%d\n",x[i]);
}
return 0;
}