Dear all,
It's been a long time that I haven't done C and I've forgot almost all about it. I'm trying to catch up with it!
Well, first I need to understand one part i.e. dynamic matrix declaration; specifically, I am trying to understand these lines of code:
Code:
// 0. write Data matrix
int size_x = 210;
int size_y = 7;
double **Data, *pDataData;
Data = (double **)malloc(size_x*sizeof(double *)+size_x*size_y*sizeof(double));
for (i = 0, pDataData = (double *)(Data+size_x); i < size_x; i++, pDataData += size_y)
Data[i]=pDataData;
for(i=0;i<size_x;i++)
for(j=0;j<size_y;j++){
Data[i][j] = *(Data_in+size_y*i+j);
//printf("%f ", Data[i][j]);
} //printf("\n\n\n\n\n");
Especially, I have problem understanding the bold lines. Could you try to explain it in a very clear way what exactly is going on here. I mean I know (by book) what malloc does and all that I just don't understand the details like what this initialization does:
Code:
pDataData = (double *)(Data+size_x)
and how a pointer to pointer equals a pointer in this line: Thank you very much in advance
Elnaz