I have troubles with understanding of the following code
1 2 3
double **zweidmatrix(int zeilen, int spalten);
void free_zweidmatrix(double **matrix, int lines);
void matrix2D_ausgabe(double **matrix, int rows, int columns);
The first line declares a pointer to pointer right? but why are the int variables in the brackets needed???
The second and the 3rd line declare functions with arguments in the brackets right??
A couple of lines below I have the following code;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
double **zweidmatrix(int lines, int spalten)
{
int l;
double **matrix;
matrix = (double **)calloc(lines, sizeof(double *));
if(NULL == matrix) printf("No virtual RAM available ... !");
for(l=0; l < lines; l++)
{
matrix[l] = (double *)calloc(spalten, sizeof(double));
if(NULL == matrix[l]) printf("No virtual RAM available ... !");
}
return matrix;
}
does it mean that the **zweidmatrix is a function? But if it is so why do I need **?? Why pointer is needed here?
According to the definition calloc allocates a block of memory for an array of num elements, each of them size bytes long, and initializes all its bits to zero. Here the array of num elements is matrix and by passing each line a block of memory is stored. Again right??
It's a function returning a pointer to pointer to double.
Line 5: double **matrix;
Line 17:return matrix;
If you want to return a double** you need the return type to be a double**
// This function should make perfectly sense:
int func1 ( /*parameters*/ )
{
int temp1;
// do stuff with temp1
return temp1;
}
// This too, working with a different return type
SomeType func2 ( /*parameters*/ )
{
SomeType temp2;
// do stuff with temp2
return temp2;
}
// Is this last function different from the other two?
double **func3 ( /*parameters*/ )
{
double **temp3;
// do stuff with temp3
return temp3;
}