Declaring and using a pointer to a function. - C Pointer

C examples for Pointer:Function Pointer

Description

Declaring and using a pointer to a function.

Demo Code

#include <stdio.h>

double square(double x);
double (*ptr)(double x);

int main( void )
{
    ptr = square;/* Initialize p to point to square(). */
    printf("%f  %f\n", square(6.6), ptr(6.6));/* Call square() two ways. */
    return 0;// w w  w . j a  va 2 s .  c om
}

double square(double x){
    return x * x;
}

Result


Related Tutorials