summaryrefslogtreecommitdiff
path: root/12_read_ptr2
diff options
context:
space:
mode:
authorHaidong Ji2022-04-15 15:51:30 -0500
committerHaidong Ji2022-04-15 15:51:30 -0500
commit442a49ad5a48d417345959b903ae6a6d32d55759 (patch)
treec7127bb497e5e439018b1915e0136eec2c9cb124 /12_read_ptr2
Great C programming funHEADmaster
Excellent fundamentals and displine training, many tools and techniques exercises: gdb, emacs, valgrind, git
Diffstat (limited to '12_read_ptr2')
-rw-r--r--12_read_ptr2/.gitignore1
-rw-r--r--12_read_ptr2/Makefile2
-rw-r--r--12_read_ptr2/README10
-rw-r--r--12_read_ptr2/answer.txt7
-rw-r--r--12_read_ptr2/grade.txt8
-rw-r--r--12_read_ptr2/test.c30
6 files changed, 58 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+
+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;
+}