box-o-sand/ex8.c

59 lines
1.7 KiB
C

#include <stdio.h>
int main(int argc, char *argv[])
{
int areas[] = {10, 12, 13, 14, 20};
char name[] = "Zed";
char full_name[] = {
'Z', 'e', 'd',
' ', 'A', '.', ' ',
'S', 'h', 'a', 'w', '\0'
};
// WARNING: On some systems you may have to change the
// %ld in this code to a %u since it will use unsigned ints
printf("The size of an int: %ld\n", sizeof(int));
printf("The size of areas (int[]): %ld\n",
sizeof(areas));
printf("The number of ints in areas: %ld\n",
sizeof(areas) / sizeof(int));
printf("The first area is %d, then 2nd %d.\n",
areas[0], areas[1]);
areas[0] = 100;
areas[2] = areas[1];
printf("Now the first area is %d and the 3rd area is %d.\n",
areas[0], areas[2]);
printf("The size of char: %ld\n", sizeof(char));
printf("The size of name (char[]): %ld\n",
sizeof(name));
printf("The number of chars: %ld\n",
sizeof(name) / sizeof(char));
printf("The size of full_name (char[]): %ld\n",
sizeof(full_name));
printf("The number of chars: %ld\n",
sizeof(full_name) / sizeof(char));
printf("name=\"%s\" and full_name=\"%s\"\n",
name, full_name);
printf("name[0] is %c.\n", name[0]);
printf("full_name[7] is %c.\n", full_name[7]);
name[0] = 'X';
printf("Now name[0] is %c.\n", name[0]);
full_name[7] = 'T';
printf("Now full_name[7] is %c.\n", full_name[7]);
printf("name=\"%s\" and full_name=\"%s\"\n",
name, full_name);
areas[2] = name[0];
printf("First area is now name[0]: %%c=%c, %%d=%d.\n",
areas[2], areas[2]);
return 0;
}