What is "int * (* pfp) ();" do in c?

What does it do?

int *(*pfp) ();
+3
source share
4 answers

int *(*pfp) ();

Creates a pointer to a function that returns int *. The name of the function pointer pfp.

Here is an example:

int* myFunc(void)
{
   return NULL;
}


int main(int argc, char**argv)
{
  int *(*pfp) (void);
  pfp = myFunc;
  return 0;
}

Note. Since the parameters of the function pointer are not (void) that you specified, this means that the list of parameters is not specified in C. In C ++, this would mean that it is a function without parameters.

+7
source

Brian explained the “what,” but if you're wondering why, here is an excerpt from Dennis Ritchie's “C Language Development” :

, C , - . NB int char , . : , , .

: , , . , , . ,

    int i, *pi, **ppi;

, , . , i, * pi ** ppi int . ,

    int f(), *f(), (*f)();

, , , , , ;

    int *api[10], (*pai)[10];

. , , .

Steve Friedl " C" Eric Giguere " C : ".

+4

pfp , ( C) int.

Using the "clockwise" rule is an effective way to decrypt complex C declarations (at least I find it effective):

0
source

Use http://www.cdecl.org/ for these things if you are not sure.

0
source

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


All Articles