Zack Li Zack Li - 3 months ago 7
C Question

C pass pointer as argument in function

I came across the following code:

int H3I_hook(int (*progress_fn)(int*), int *id)
{
...
}


I don't understand the purpose of
(int*)
at the end of the first argument?

Answer

Demystifying:

int (*progress_fn)(int*)

it can be interpreted like below:

int (*progress_fn)(int*)
 ^       ^          ^
 |       |          |___________ pointer to integer as argument
 |       |                                          ^
 |     pointer to any function that has | and takes |
 |                                      V
 |__________________________return type an integer