summaryrefslogtreecommitdiff
path: root/24_read_arr3
diff options
context:
space:
mode:
authorHaidong Ji2022-04-15 15:51:30 -0500
committerHaidong Ji2022-04-15 15:51:30 -0500
commit442a49ad5a48d417345959b903ae6a6d32d55759 (patch)
treec7127bb497e5e439018b1915e0136eec2c9cb124 /24_read_arr3
Great C programming funHEADmaster
Excellent fundamentals and displine training, many tools and techniques exercises: gdb, emacs, valgrind, git
Diffstat (limited to '24_read_arr3')
-rw-r--r--24_read_arr3/README3
-rw-r--r--24_read_arr3/answer.txt13
-rw-r--r--24_read_arr3/grade.txt5
-rw-r--r--24_read_arr3/test.c31
4 files changed, 52 insertions, 0 deletions
diff --git a/24_read_arr3/README b/24_read_arr3/README
new file mode 100644
index 0000000..3329694
--- /dev/null
+++ b/24_read_arr3/README
@@ -0,0 +1,3 @@
+Execute the code in test.c by hand, and place the resulting
+output in a file called "answer.txt".
+As always, compile and run test.c to check your work, and submit.
diff --git a/24_read_arr3/answer.txt b/24_read_arr3/answer.txt
new file mode 100644
index 0000000..7057c8e
--- /dev/null
+++ b/24_read_arr3/answer.txt
@@ -0,0 +1,13 @@
+x = 1
+*p = 7
+**q= 4
+1
+2
+3
+99
+5
+6
+42
+8
+9
+*q=9
diff --git a/24_read_arr3/grade.txt b/24_read_arr3/grade.txt
new file mode 100644
index 0000000..1f697dc
--- /dev/null
+++ b/24_read_arr3/grade.txt
@@ -0,0 +1,5 @@
+Grading at Sat 20 Nov 2021 09:23:08 PM UTC
+Your file matched the expected output
+Your output matched what we expected
+
+Overall Grade: A
diff --git a/24_read_arr3/test.c b/24_read_arr3/test.c
new file mode 100644
index 0000000..c91dcfb
--- /dev/null
+++ b/24_read_arr3/test.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int* aFunction(int x, int *p, int ** q) {
+ printf("x = %d\n", x);
+ printf("*p = %d\n", *p);
+ printf("**q= %d\n", **q);
+ *p = 42;
+ **q = 99;
+ *q = &p[1];
+ return &p[2];
+}
+
+int main (void) {
+ int anArray[3][3] = { {1,2,3},
+ {4,5,6},
+ {7,8,9} };
+
+ int * p = anArray[1];
+ int * q = aFunction(anArray[0][0],
+ anArray[2],
+ &p);
+ for (int i =0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ printf("%d\n", anArray[i][j]);
+ }
+ }
+ printf("*q=%d\n", *q);
+
+ return EXIT_SUCCESS;
+}