home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tyc / list15_8.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-16  |  439 b   |  28 lines

  1.  /* Demonstration of declaring and using a pointer to a function. */
  2.  
  3.  #include <stdio.h>
  4.  
  5.  /* The function prototype. */
  6.  
  7.  float square(float x);
  8.  
  9.  /* The pointer declaration. */
  10.  
  11.  float (*p)(float x);
  12.  
  13.  main()
  14.  {
  15.     /* Initialize p to point to square(). */
  16.  
  17.       p = square;
  18.  
  19.      /* Call square() two ways. */
  20.  
  21.      printf("%f  %f", square(6.6), p(6.6));
  22.  }
  23.  
  24.  float square(float x)
  25.  {
  26.      return x * x;
  27.  }
  28.