Facebook
From Soiled Mockingbird, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 221
  1. #include <stdio.h>
  2. int main(int argc, char *argv[])
  3. {
  4.  int areas[] = {10, 12, 13, 14, 20};
  5.  char name[] = "Zed";
  6.  char full_name[] = {
  7.  'Z', 'e', 'd',
  8.  ' ', 'A', '.', ' ',
  9.  'S', 'h', 'a', 'w', '\0'
  10.  };
  11.  // WARNING: On some systems you may have to change the
  12.  // %ld in this code to a %u since it will use unsigned ints
  13.  printf("The size of an int: %ld\n", sizeof(int));
  14.  printf("The size of areas (int[]): %ld\n",
  15.  sizeof(areas));
  16.  printf("The number of ints in areas: %ld\n",
  17.  sizeof(areas) / sizeof(int));
  18.  printf("The first area is %d, the 2nd %d.\n",
  19.  areas[0], areas[1]);
  20.  printf("The size of a char: %ld\n", sizeof(char));
  21.  printf("The size of name (char[]): %ld\n",
  22.  sizeof(name));
  23.  printf("The number of chars: %ld\n",
  24.  sizeof(name) / sizeof(char));
  25.  printf("The size of full_name (char[]): %ld\n",
  26.  sizeof(full_name));
  27.  printf("The number of chars: %ld\n",
  28.  sizeof(full_name) / sizeof(char));
  29.  printf("name=\"%s\" and full_name=\"%s\"\n",
  30.  name, full_name);
  31.  return 0;
  32. }
  33.