summaryrefslogtreecommitdiff
path: root/11_read_ptr1
diff options
context:
space:
mode:
Diffstat (limited to '11_read_ptr1')
-rw-r--r--11_read_ptr1/.gitignore1
-rw-r--r--11_read_ptr1/Makefile2
-rw-r--r--11_read_ptr1/README10
-rw-r--r--11_read_ptr1/answer.txt4
-rw-r--r--11_read_ptr1/grade.txt8
-rw-r--r--11_read_ptr1/test.c26
6 files changed, 51 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+
+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;
+}