home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc / qc25 / pfunc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-15  |  422 b   |  22 lines

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