From 0cbe502348da76d01fe446fbf31423fc418e678c Mon Sep 17 00:00:00 2001 From: zleyyij <75810274+zleyyij@users.noreply.github.com> Date: Fri, 1 Nov 2024 13:23:59 -0600 Subject: [PATCH] vault backup: 2024-11-01 13:23:59 --- .../ECE1400/Chapter 11 Exercises.md | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/education/software development/ECE1400/Chapter 11 Exercises.md b/education/software development/ECE1400/Chapter 11 Exercises.md index 68d5183..a65b547 100644 --- a/education/software development/ECE1400/Chapter 11 Exercises.md +++ b/education/software development/ECE1400/Chapter 11 Exercises.md @@ -5,4 +5,25 @@ g. `*&i` > 2. If `i` is an `int` variable and `p` and `q` are pointers to `int`, which of the following assignments are legal? -a. \ No newline at end of file +e. `p = *&q;` +f. `p = q;` +i. `*p = *q` + +> 3. The following function supposedly computes the sum and average of the numbers in the array `a`, which has length `n`. `avg` and `sum` point to the variables that the function should modify, unfortunately the function contains several errors, find and correct them. + +```c +void avg_sum(double a[], int n, double *avg, double *sum) +{ +int i; + +// This was assigning a pointer to a float, +// the dereference operator was missing +*sum = 0.0; +for (i = 0; i < n; i++) + // This wasn't increasing the value + // `sum` points to, it was modifying the address the pointer po + (*sum) += a[i]; +avg = sum / n; + +} +``` \ No newline at end of file