I want to define multiple array pointers in my main, and then pass these pointers into a function to allocate memory for them. The thing is that the size of the array is not known before entering somefunction
. I am not sure how to do this or if there is a better way to do this, but I tried with this code, which did not work.
void somefunction(int *arr1,int *arr2){
int M = 3;
int N = 2;
arr1 = (int*)malloc(M*sizeof(int));
arr2 = (int*)malloc(N*sizeof(int));
}
int main(){
int* array_1;
int* array_2;
somefunction(array_1,array_2);
//Here I want array_1 to be of size M and array_2 of size N
}