3

Please highlight the difference between the following function declarations:

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

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

vikaspraj
  • 1,003
  • 1
  • 9
  • 10

3 Answers3

6
  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.

Antoine
  • 5,158
  • 1
  • 24
  • 37
5

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.)

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
0

EDIT: Nevermind, I misread the declarations. Sorry.

The thing is, you're declaring function pointers, not functions as people already pointed out.

Victor
  • 385
  • 2
  • 7