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 --- 24_read_arr3/README | 3 +++ 24_read_arr3/answer.txt | 13 +++++++++++++ 24_read_arr3/grade.txt | 5 +++++ 24_read_arr3/test.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 24_read_arr3/README create mode 100644 24_read_arr3/answer.txt create mode 100644 24_read_arr3/grade.txt create mode 100644 24_read_arr3/test.c (limited to '24_read_arr3') 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 +#include + +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; +} -- cgit v1.2.3