0

How to call with function pointer this function?

    double a(double *a){
    return *a;
}

I try this but without luck:

double (*p)(*double) = &a;

I didn't find much good tutorial for those purpose, can you refer me to some good link.

2 Answers 2

4

Like this:

double (*p)(double*) = &a;

As you can see, the function signature in the type of the function pointer is written in exactly the same way as in the actual function declaration (and you don't need to the arguments names).

Sign up to request clarification or add additional context in comments.

1 Comment

The precise form used in the question (double *a) suggested that the * belongs to a, not double. That is probably the root cause.
0

Altered slightly so not everything is called a:

double deref(double *a)
{
    return *a;
}

double test()
{
    double (*deref_pointer)(double*) = deref;

    double value = 3.14;

    return deref_pointer(&value);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.