Very simple question c

since we use pointers in the argument list of functions like

void f(int *); 

This means that this function will get a pointer to an integer but what does it mean

void f(int ***); 

and

void f(int **=0)
+3
source share
6 answers
void f(int ***); 

means that the function receives a pointer to a pointer to a pointer to an int. This would work with this:

int x=42;
int *px=&x;
int **ppx=&px;
int ***pppx=&ppx;
f(pppx);

Now about the second, its a function that gets a pointer to a pointer to an int, and if you give nothing, by default it is 0.

int x=42;
int *px=&x;
int **ppx=&px;
f(ppx);  // pt to pt to x
f();     // same as f(0)

UPDATE:

The practical use of this type of double pointer is a memory allocation program, such as:

bool alloc(T **mem, int count);

true/false , , , , , :

T *mem;
verify(alloc(&mem, 100));

, , . mem .

, , , ( ).

+15
int *** 

int. (((int*)*)*).

void f(int **=0)

int , , 0.

+5
void f(int ***); 

f int.

void f(int **=0)

int , 0 (i.e null)

+4
void f(int ***);

int (, , ).

void f(int **=0)  

int, 0 ( ... 0, int), ( ).

+1
+1
void f(int ***); 

, int. , - ( ) , , , , . 3 20 C ++ 2.

-3

Source: https://habr.com/ru/post/1728756/


All Articles