home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch4 / address3.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  1KB  |  31 lines

  1. /*                    address3.c
  2.  *
  3.  *   Synopsis  - Uses pointers to print the addresses of a char
  4.  *               variable and an int variable and the address of 
  5.  *               the next available memory location for each 
  6.  *               data type.
  7.  *
  8.  *   Objective - Illustrates what is meant by a pointer-to-int
  9.  *               being a separate data type. Demonstrates syntax 
  10.  *               of declaring a pointer-to-char variable, 
  11.  *               initialization of pointer variables, and 
  12.  *               the result of adding 1 to pointer variables 
  13.  *               of different types.
  14.  */
  15.  
  16. /* Include Files */
  17. #include <stdio.h>
  18.  
  19. int main( void )
  20. {
  21.      int intvar, *int_ptr;                                                  /* Note 1 */
  22.      char charvar, *char_ptr = &charvar;                                    /* Note 2 */
  23.  
  24.      int_ptr = &intvar;
  25.  
  26.      printf( "The address of charvar is %p.\n", char_ptr );
  27.      printf( "The next character could be stored at %p.\n", char_ptr + 1 ); /* Note 3 */
  28.      printf( "The address of intvar is %p.\n", int_ptr );
  29.      printf( "The next integer could be stored at %p.\n", int_ptr + 1 );    /* Note 4 */
  30.      return 0;
  31. }