Search code examples
cfunctionfunction-pointers

How to understand that function / pointer declaration?


In C, one can declare pointers to functions like that:

void (*Func1)(int)

I believe that I've understood what this means (in this case, a pointer to a function which returns void and takes an int as parameter) and how to declare and use such pointers.

However, I now have come across declarations like the following:

void (*Func2(int, int))(int)

I am struggling with understanding this syntax. What exactly is declared here? Probably it is a pointer to a function, but I always thought that the closing round parenthesis after the pointer's name is necessary then, so I am completely unsure now.

Could anybody explain, step by step, what the above declaration means?


Solution

  • From https://cdecl.org/?q=void+%28*Func2%28int%2C+int%29%29%28int%29

    void (*Func2(int, int))(int)

    declare Func2 as function (int, int) returning pointer to function (int) returning void