From 442a49ad5a48d417345959b903ae6a6d32d55759 Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Fri, 15 Apr 2022 15:51:30 -0500 Subject: Great C programming fun Excellent fundamentals and displine training, many tools and techniques exercises: gdb, emacs, valgrind, git --- 11_read_ptr1/.gitignore | 1 + 11_read_ptr1/Makefile | 2 ++ 11_read_ptr1/README | 10 ++++++++++ 11_read_ptr1/answer.txt | 4 ++++ 11_read_ptr1/grade.txt | 8 ++++++++ 11_read_ptr1/test.c | 26 ++++++++++++++++++++++++++ 6 files changed, 51 insertions(+) create mode 100644 11_read_ptr1/.gitignore create mode 100644 11_read_ptr1/Makefile create mode 100644 11_read_ptr1/README create mode 100644 11_read_ptr1/answer.txt create mode 100644 11_read_ptr1/grade.txt create mode 100644 11_read_ptr1/test.c (limited to '11_read_ptr1') diff --git a/11_read_ptr1/.gitignore b/11_read_ptr1/.gitignore new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/11_read_ptr1/.gitignore @@ -0,0 +1 @@ +test diff --git a/11_read_ptr1/Makefile b/11_read_ptr1/Makefile new file mode 100644 index 0000000..f337094 --- /dev/null +++ b/11_read_ptr1/Makefile @@ -0,0 +1,2 @@ +test: test.c + gcc -o test -pedantic -std=gnu99 -Wall -Werror test.c diff --git a/11_read_ptr1/README b/11_read_ptr1/README new file mode 100644 index 0000000..6a18875 --- /dev/null +++ b/11_read_ptr1/README @@ -0,0 +1,10 @@ + 1. Execute the code in "test.c" by hand, and write the output + printed to the terminal into a file called "answer.txt" + + 2. Create a Makefile to compile test.c into a program called "test" + + 3. Run test and use its output to check your work. + + 4. Submit your Makefile and your answer.txt file + + diff --git a/11_read_ptr1/answer.txt b/11_read_ptr1/answer.txt new file mode 100644 index 0000000..22c9abe --- /dev/null +++ b/11_read_ptr1/answer.txt @@ -0,0 +1,4 @@ +In f, *a = 3, b = 4 +In g, x = 7, *y = 8 +Back in f, *a = 7, b = 0 +In main: x = 7, y = 4 diff --git a/11_read_ptr1/grade.txt b/11_read_ptr1/grade.txt new file mode 100644 index 0000000..ed181ad --- /dev/null +++ b/11_read_ptr1/grade.txt @@ -0,0 +1,8 @@ +Grading at Sun 10 Oct 2021 12:55:58 AM UTC +Attempting to compile test.c +gcc -o test -pedantic -std=gnu99 -Wall -Werror test.c +compiled +Your file matched the expected output +Your output matched what we expected + +Overall Grade: PASSED diff --git a/11_read_ptr1/test.c b/11_read_ptr1/test.c new file mode 100644 index 0000000..5d91622 --- /dev/null +++ b/11_read_ptr1/test.c @@ -0,0 +1,26 @@ +#include +#include + +void g(int x, int * y) { + printf("In g, x = %d, *y = %d\n", x, *y); + x++; + *y = *y - x; + y = &x; +} + +void f(int * a, int b) { + printf("In f, *a = %d, b = %d\n", *a, b); + *a += b; + b *= 2; + g(*a, &b); + printf("Back in f, *a = %d, b = %d\n", *a, b); +} + + +int main(void) { + int x = 3; + int y = 4; + f(&x, y); + printf("In main: x = %d, y = %d\n", x, y); + return EXIT_SUCCESS; +} -- cgit v1.2.3