Home Segments Index Top Previous Next

59: Sidetrip

If you are curious about how much memory your C implementation allocates for the various data types, you can compile and execute the following program, which uses the sizeof operator to determine data-type size:

#include   
main ( ) { 
  printf ("Data Type    Bytes\n"); 
  printf ("char         %i\n", sizeof (char)); 
  printf ("short        %i\n", sizeof (short)); 
  printf ("int          %i\n", sizeof (int)); 
  printf ("long         %i\n", sizeof (long)); 
  printf ("float        %i\n", sizeof (float)); 
  printf ("double       %i\n", sizeof (double)); 
  printf ("long double  %i\n", sizeof (long double)); 
}