home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch1 / function.x < prev    next >
Text File  |  2005-06-16  |  1KB  |  42 lines

  1. /*                    function.c 
  2.  *
  3.  *    Synopsis-                Makes four calls to the function f() and displays
  4.  *                    values involving the return value of the function.
  5.  *    Objective-                To demonstrate a function that 1) takes a 
  6.  *                    parameter, and 2) returns a value. Three 
  7.  *                    versions of function calls to f() are also 
  8.  *                    demonstrated.
  9.  */
  10.  
  11. /* Include Files */
  12. #include <stdio.h>
  13.  
  14. /* Function Prototypes */
  15. int f( int x );                                                            /* Note 1 */
  16. /* PRECONDITION:                    x can be any integer
  17. *
  18. * POSTCONDITION:                    The value returned is x+3
  19. */
  20.  
  21. int main(void) 
  22. {
  23.     int x, y, z; 
  24.  
  25.     z = 4;
  26.     y = f(z);                                                        /* Note 2 */
  27.     printf( "y is %d\n", y );
  28.  
  29.     x = y + f(3);                                                        /* Note 3 */
  30.     printf( "The value of x is %d\n", x );
  31.     
  32.     f(x);                                                        /* Note 4 */
  33.     printf( "The value of f(5) is %d\n", f(5) );                                                        /* Note 5 */
  34.     return 0;
  35. }
  36.  
  37. /*******************************                f()****************************/
  38.  
  39. int f(int x)                                                            /* Note 6 */
  40. {
  41.     return x + 3;                                                        /* Note 7 */
  42. }