home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / learn / pfunc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-10  |  424 b   |  23 lines

  1. /* PFUNC.C: Passing pointers to a function. */
  2.  
  3. #include <stdio.h>
  4.  
  5. void swap( int *ptr1, int *ptr2 );
  6.  
  7. main()
  8. {
  9.    int first = 1, second = 3;
  10.    int *ptr = &second;
  11.    printf( "first: %d  second: %d\n", first, *ptr );
  12.    swap( &first, ptr );
  13.    printf( "first: %d  second: %d\n", first, *ptr );
  14. }
  15.  
  16. void swap( int *ptr1, int *ptr2 )
  17. {
  18.    int temp;
  19.    temp = *ptr1;
  20.    *ptr1 = *ptr2;
  21.    *ptr2 = temp;
  22. }
  23.