Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are these lines of code in C programming the same

Tags:

c

Are these 2 lines of code the same ??

line 1:

void (**foo)(int)

line 2

void *(*foo)(int)

Kindly help me understand on what is happening.

like image 542
Pisers Avatar asked Oct 17 '25 19:10

Pisers


1 Answers

They are not the same.

void (**foo)(int);

foo is a pointer to a pointer to a function that takes an int parameter and returns void.

void *(*foo)(int):

foo is a pointer to a function that takes an int parameter and returns a pointer to void.

Postfix operators like () and [] have higher precedence than unary *, so

T *a[N];    // a is an array of pointer to T
T (*a)[N];  // a is a pointer to an array of T

T *f();     // f is a function returning pointer to T
T (*f)();   // f is a pointer to a function returning T
like image 118
John Bode Avatar answered Oct 19 '25 10:10

John Bode