From 58f158f89e2064ac4cf9b764588772950e9d5c3d Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 12 Apr 2016 11:51:59 -0400 Subject: [PATCH] ex8 --- lcthw-remnants-2/.gitignore | 1 + lcthw-remnants-2/ex8.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 lcthw-remnants-2/ex8.c diff --git a/lcthw-remnants-2/.gitignore b/lcthw-remnants-2/.gitignore index c6be593..f37cd25 100644 --- a/lcthw-remnants-2/.gitignore +++ b/lcthw-remnants-2/.gitignore @@ -4,3 +4,4 @@ ex4 ex5 ex6 ex7 +ex8 diff --git a/lcthw-remnants-2/ex8.c b/lcthw-remnants-2/ex8.c new file mode 100644 index 0000000..072beac --- /dev/null +++ b/lcthw-remnants-2/ex8.c @@ -0,0 +1,36 @@ +#include + +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 first area is %d, the 2nd %d.\n", + areas[0], areas[1]); + + printf("The size of a 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); + + return 0; +}