jimih22612
jimih22612

Reputation: 11

Pointers looking like function pointers

As I starting to learn C++, this question may be stupid but I do not understand some strange pointers.

void (*p1(int*))(float*);
int* (*(*p2)(double(*fp1)(char), int*))(float *);
int* (*(*p3)(double(*)(char), int*))(double*);

I think p2 and p3 are function pointers pointing to a function that returns a pointer to int but I am totally lost about the rest. Also I don't understand p1 at all.

Can anyone help me please?

Thanks.

Upvotes: 0

Views: 50

Answers (2)

M.M
M.M

Reputation: 141554

Because of p1(int*) we know that p1 is a function taking argument int*. The return type of the function is the rest of the declaration once we delete the part we already analyzed, void (*)(float*) (i.e. pointer to function taking float * and returning void.

p2 and p3 have the same form, just p2 gives a name to the function parameter. So I will only address one of them, p3.

Because of (*p3)(double(*)(char), int *) we know that (*p3) is a function taking arguments double(*)(char) and int *. The return type of the function is the rest of the declaration without the part we already analyzed, i.e. int*(*)(double *). Since (*p3) has that function type, then p3's type is: pointer to that function.

Upvotes: 1

David G
David G

Reputation: 96800

p1 is a function that returns a pointer to a function. You are correct about p2. It is a pointer to a function that takes two arguments - a pointer to a function and a pointer to an int - and returns a pointer to a function. p3 is the same.

Upvotes: 0

Related Questions