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 --- 12_read_ptr2/.gitignore | 1 + 12_read_ptr2/Makefile | 2 ++ 12_read_ptr2/README | 10 ++++++++++ 12_read_ptr2/answer.txt | 7 +++++++ 12_read_ptr2/grade.txt | 8 ++++++++ 12_read_ptr2/test.c | 30 ++++++++++++++++++++++++++++++ 6 files changed, 58 insertions(+) create mode 100644 12_read_ptr2/.gitignore create mode 100644 12_read_ptr2/Makefile create mode 100644 12_read_ptr2/README create mode 100644 12_read_ptr2/answer.txt create mode 100644 12_read_ptr2/grade.txt create mode 100644 12_read_ptr2/test.c (limited to '12_read_ptr2') diff --git a/12_read_ptr2/.gitignore b/12_read_ptr2/.gitignore new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/12_read_ptr2/.gitignore @@ -0,0 +1 @@ +test diff --git a/12_read_ptr2/Makefile b/12_read_ptr2/Makefile new file mode 100644 index 0000000..f337094 --- /dev/null +++ b/12_read_ptr2/Makefile @@ -0,0 +1,2 @@ +test: test.c + gcc -o test -pedantic -std=gnu99 -Wall -Werror test.c diff --git a/12_read_ptr2/README b/12_read_ptr2/README new file mode 100644 index 0000000..6a18875 --- /dev/null +++ b/12_read_ptr2/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/12_read_ptr2/answer.txt b/12_read_ptr2/answer.txt new file mode 100644 index 0000000..b31f233 --- /dev/null +++ b/12_read_ptr2/answer.txt @@ -0,0 +1,7 @@ +**r = 12 +**s = 80 +x = 92 +*p = -7 +*q = 75 +a = 75 +b = -7 diff --git a/12_read_ptr2/grade.txt b/12_read_ptr2/grade.txt new file mode 100644 index 0000000..b31de05 --- /dev/null +++ b/12_read_ptr2/grade.txt @@ -0,0 +1,8 @@ +Grading at Sun 10 Oct 2021 02:24:23 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/12_read_ptr2/test.c b/12_read_ptr2/test.c new file mode 100644 index 0000000..ffa4754 --- /dev/null +++ b/12_read_ptr2/test.c @@ -0,0 +1,30 @@ +#include +#include + +int f(int ** r, int ** s) { + int temp = ** r; + int temp2 = **s; + int * z = *r; + *r = *s; + *s = z; + printf("**r = %d\n",**r); + printf("**s = %d\n",**s); + *z += 3; + **s -= 8; + **r -= 19; + return temp + temp2; +} + +int main(void) { + int a = 80; + int b = 12; + int * p = &a; + int * q = &b; + int x = f(&p, &q); + printf("x = %d\n", x); + printf("*p = %d\n", *p); + printf("*q = %d\n", *q); + printf("a = %d\n", a); + printf("b = %d\n", b); + return EXIT_SUCCESS; +} -- cgit v1.2.3