home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 July / APC47-1.ISO / workshop / c / pointer.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-05  |  985 b   |  34 lines

  1. // **************************************************************
  2. // pointer.cpp
  3. // Example program for Simple C++
  4. //
  5. // (c) 1999 Emmenjay Consulting Pty Ltd                          
  6. //                                                               
  7. // History                                                       
  8. // 05/05/99 MJS  Initial Coding.                                 
  9. //                                                               
  10. // **************************************************************
  11.  
  12. #include <iostream>
  13.  
  14. int main( void )
  15. {
  16.     int i=3, j=6;
  17.     int *p;
  18.  
  19.     std::cout << "i and j = " << i 
  20.               << " and " << j << '\n';
  21.     p = &i;
  22.     std::cout << "*p (pointing to i) = " 
  23.               << *p << '\n';
  24.     p = &j;
  25.     std::cout << "*p (pointing to j) = " 
  26.               << *p << '\n';
  27.  
  28.     *p = 9;  // THIS MODIFIES J
  29.     std::cout << "i and j = " << i 
  30.               << " and " << j << '\n';
  31.  
  32.     return 0;
  33. }
  34.