0

what's the difference between the second and third line:

int (*myFunction)() = fooFunction;
(*fooFunction)();
fooFunction();

Why do both do the same thing? Is it just how C++'s syntax is? I thought that a function pointer needs to be dereferenced in order to call it. How does the third line work, it isn't dereferenced.

  • You may ask a similar question about `int (*myFunction)() = fooFunction;` and `int (*myFunction)() = &fooFunction;`: *I thought that an address of a function needs to be taken in order to get a function pointer.* – 273K Mar 03 '22 at 03:39
  • You can also write `int (*myFunction)() = &&&&fooFunction;`. A pointer-to-function remains a pointer-to-function regardless of what you do to it. – Pete Becker Mar 03 '22 at 03:48

0 Answers0