Up through lcthw ex12

This commit is contained in:
Dan Buch 2024-04-18 18:28:12 -04:00
parent 8af4f619f4
commit 32e70e96ce
Signed by: meatballhat
GPG Key ID: A12F782281063434
3 changed files with 35 additions and 2 deletions

1
lcthw/.gitignore vendored
View File

@ -5,3 +5,4 @@ ex8
ex9
ex10
ex11
ex12

View File

@ -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

32
lcthw/ex12.c Normal file
View File

@ -0,0 +1,32 @@
#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',
};
// 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;
}