diff --git a/lcthw/.gitignore b/lcthw/.gitignore index 362c151..6add8a7 100644 --- a/lcthw/.gitignore +++ b/lcthw/.gitignore @@ -5,3 +5,4 @@ ex8 ex9 ex10 ex11 +ex12 diff --git a/lcthw/Makefile b/lcthw/Makefile index 79c01a4..de28cc9 100644 --- a/lcthw/Makefile +++ b/lcthw/Makefile @@ -1,7 +1,7 @@ CFLAGS ?= -Wall -g GDBRUN = gdb --batch --ex run --ex bt --ex q --args -BUILD_TARGETS = ex1 ex3 ex7 ex8 ex9 ex10 ex11 -TEST_TARGETS = ex1 ex3 ex7 ex8 ex9 ex11 +BUILD_TARGETS = ex1 ex3 ex7 ex8 ex9 ex10 ex11 ex12 +TEST_TARGETS = ex1 ex3 ex7 ex8 ex9 ex11 ex12 .PHONY: all all: build test diff --git a/lcthw/ex12.c b/lcthw/ex12.c new file mode 100644 index 0000000..78e218e --- /dev/null +++ b/lcthw/ex12.c @@ -0,0 +1,32 @@ +#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', + }; + + // 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, 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; +}