Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between these two confusing function pointer notations in C?

What is the difference between these two function pointer notations in C?

void (*a[]()) and void (*a)()[]

Do they both represent same - a as an array of pointers to functions - or does the second one represent a pointer to an array of functions?

How should I call these functions - say void (*a[]()) = {swap, add, sub, prod};?

Does that mean that a is an array of function pointers of 4 elements and swap, add, sub, prod's address are there in the a[0]...a[3]. How should I invoke these functions, like this?

*a[i]()

or like this?

a[i]()
like image 992
Raulp Avatar asked Jul 30 '26 17:07

Raulp


1 Answers

Use cdecl.org to figure this stuff out until you can do it without thinking about it.

void (*a[]()): declare a as array of function returning pointer to void

whereas

void (*a)()[]: declare a as pointer to function returning array of void

The latter is invalid C.

like image 117
Mahmoud Al-Qudsi Avatar answered Aug 01 '26 06:08

Mahmoud Al-Qudsi