Just a quick question to satisfy my curiosity:
Well, I managed to create an array using dynamic memory allocation (MxN), as shown:
matrix1=(double **)malloc(M*sizeof(double*)){
for (i1=0;i1<1;i1++)
matrix1[i1]=(double*)malloc(N*sizeof(double)); }
and say I have already filled up the contents of this array completely and correctly, and that I can free up the memory I've reserved later on
i then pass this array to a function by calling the function through this function call:
print_elements(&M,&N,matrix1);
with the function being called being a simple printing function:
void print_elements(int* M, int* N, double** print){
int rows_p, cols_p;
printf("\n\nYour matrix is: \n");
for(rows_p=0;rows_p<*M;rows_p++){
for(cols_p=0;cols_p<*N;cols_p++){
printf("%.2lf ", print[rows_p][cols_p]); }
printf("\n");}}
my question is, did I pass the array matrix1 by reference? I know that arrays are passed to a function by default by reference but I just wanted to know if it is indeed the case and if I even did it the way it really should be done?
appreciate any help