1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

#include <stdio.h>
#include <math.h>
double integrate (double (*)(double), double, double);


double integrate (double (*fptr)(double), double a, double b)
{
double x, sum = 0.0, delta_x = 0.1;
for (x = a; x <= b; x = x + delta_x)
sum = sum + delta_x * (*fptr)(x);
return sum;
}


void initial (int x, char* y) {
printf ("fewer than %d chars in %s\n", x, y);
}
void main (void) {
double (*fptr)();
/* want a pointer to a function not */
void (*funptr)();/*a function that returns a pointer */


funptr = initial;


initial (64, "Help me, please?") ;
(*funptr) (24, "Why, Oh why?") ;
/* next example*/
fprintf (stdout, "Integral of sine is %f\n",
integrate (sin, 0.0, 1.1));

fptr = cos;
fprintf (stdout, "Cosine integral is %f\n",
integrate ((*fptr), 0.0, 1.1));

}

March 3, 1998

Page 1

C201/TAM