2

I'd like to know what is the difference between these two (seemingly correct) ways of passing a function to another function:

void fun(int p(int x));

void fun(int (*p)(int x));

Also, I know that in the second case we're passing a function pointer, but is the first approach also a function pointer (but without the star)?

JeJo
  • 30,635
  • 6
  • 49
  • 88
PhantomR
  • 605
  • 4
  • 16
  • 1
    Does [this](https://stackoverflow.com/questions/7111251/pass-function-by-value-instead-of-function-pointer) answer your question? – Cory Kramer May 10 '18 at 12:35
  • 2
    It is the same behavior of passing an array, in the first case you pass a function object that is referred by a pointer to a function (be careful a function pointer could be different from a standard pointer) using an implicit compiler conversion, in the second case you explicitly pass a function pointer. – Frankie_C May 10 '18 at 12:42
  • Thank you both for your help. @CoryKramer That was actually helpful information. I also liked the array analogy :). – PhantomR May 11 '18 at 20:52

0 Answers0