Pisers
Pisers

Reputation: 99

Are these lines of code in C programming the same

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.

Upvotes: 4

Views: 69

Answers (1)

John Bode
John Bode

Reputation: 123468

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

Upvotes: 5

Related Questions