Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain the difference in these function pointer declarations

Please highlight the difference between the following function declarations:

  1. void (*p) (void *a[], int n)

  2. void *(*p[]) (void *a, int n)

like image 433
vikaspraj Avatar asked Jun 25 '26 05:06

vikaspraj


2 Answers

  1. void (*p) (void *a[], int n) defines a pointer to a function that takes a void* array and an int as parameter

  2. void *(*p[]) (void *a, int n) defines an array of pointers to functions that return a void*, and take a void* and an int as parameter.

like image 141
Antoine Avatar answered Jun 26 '26 20:06

Antoine


Neither are function declarations, so there's nothing to explain.

Both are, however, declarations of function pointers. There is an excellent tutorial website that you should consume.

I should also suggest the handy program cdecl (or its online incarnations); perhaps you'd like to give it a shot yourself before someone reveals the answer for you?

(You need to type void *(*p[]) (void *, int) into the website; i.e. no identifiers for the function arguments.)

like image 30
Kerrek SB Avatar answered Jun 26 '26 20:06

Kerrek SB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!