code interpretation

Hi,

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??

10x
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**
I hate pointers

What do you mean? Tha code should not work? Actually it works...

After I have done so many tuts for pointers I still cannot understand how they work and why they are needed...

See this example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 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;
}
// Is this last function different from the other two?


Still I do not know the reason for using ** I cannot answer this question....

The only thing I (may be) know is that func3 points to a pointer which points to a double, therefore temp3 is double

But which is this pointer which func3 points to?
func3 is a function, it doesn't point anywhere.
See this:
1
2
3
4
5
6
7
8
typedef double** SomeType;

SomeType func2 ( /*parameters*/ )
{
     SomeType temp2;
     // do stuff with temp2
     return temp2;
}
Pointers ( and pointers to pointers ) are just as other types
Topic archived. No new replies allowed.