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

  1. /*                       md.c
  2.  *
  3.  *   Synopsis  - Displays information about a 2 x 3 array of
  4.  *               characters.
  5.  *
  6.  *   Objective - To illustrate the relationship between different
  7.  *               expressions related to an array.
  8.  */
  9.  
  10. /* Include Files */
  11. #include <stdio.h>
  12.  
  13. /* Constant Definitions */
  14. #define ROWS       2
  15. #define COLUMNS    3
  16.  
  17. int main( void )
  18. {
  19.      static char t[ROWS][COLUMNS] = { { 'a', 'b', 'c' },
  20.                                       { 'd', 'e', 'f' }  };
  21.  
  22.      printf( "sizeof( char )   %d\n", sizeof( char ) );
  23.  
  24.      printf( "   2 X 3 array\n" );
  25.      printf( "--------------------\n" );
  26.      printf( "t                %p\n", t );                  /* Note 1 */
  27.                                                             /* Note 2 */
  28.      printf( "sizeof(t)        %d\n\n", sizeof(t) );
  29.  
  30.      printf( "  First 1 X 3 array\n" );
  31.      printf( "--------------------\n" );
  32.      printf( "*t               %p\n", *t );                 /* Note 1 */
  33.                                                             /* Note 2 */
  34.      printf( "sizeof(*t)       %d\n\n", sizeof(*t) );
  35.  
  36.      printf( "First element in array\n" );
  37.      printf( "----------------------\n" );
  38.      printf( "&t[0][0]         %p\n", &t[0][0] );           /* Note 1 */
  39.                                                             /* Note 2 */
  40.      printf( "sizeof(&t[0][0]) %d\n", sizeof( &t[0][0] ) );
  41.      printf( "t[0][0]          %c\n", t[0][0] );        /* Note 3 */
  42.      printf( "sizeof (t[0][0]) %d\n", sizeof( t[0][0] ) );
  43.      printf( "**t              %c\n\n", **t );              /* Note 3 */
  44.  
  45.      printf( "Second 1 X 3 array\n" );
  46.      printf( "-------------------\n" );
  47.      printf( "t+1              %p\n", t+1 );                /* Note 4 */
  48.      printf( "sizeof(t+1)      %d\n", sizeof( t+1 ) );
  49.                                                             /* Note 4 */
  50.      printf( "*(t+1)           %p\n", *( t+1 ) );
  51.      printf( "sizeof (*(t+1))  %d\n", sizeof( *( t+1 ) ) );
  52.                                                             /* Note 5 */
  53.      printf( "*(t+1) +2        %p\n", *( t+1 ) + 2 );
  54.      printf( "*(*(t+1) +2)     %c\n", *( *( t+1 ) + 2 ) );
  55.      return 0;
  56. }
  57.