From 1404a579293c7fdb2e2674c107ff50657417767b Mon Sep 17 00:00:00 2001 From: zleyyij <75810274+zleyyij@users.noreply.github.com> Date: Sat, 12 Oct 2024 21:02:02 -0600 Subject: [PATCH] vault backup: 2024-10-12 21:02:02 --- .../ECE1400/Chapter 9 Exercises.md | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/education/software development/ECE1400/Chapter 9 Exercises.md b/education/software development/ECE1400/Chapter 9 Exercises.md index ebc3876..e01a084 100644 --- a/education/software development/ECE1400/Chapter 9 Exercises.md +++ b/education/software development/ECE1400/Chapter 9 Exercises.md @@ -50,18 +50,29 @@ Parameters must contain a type annotation but they do not need to specify a name > 9. What will be the output of the following program? ```c -double triangle_area(double base, double height) +#include + +void swap (int a, int b); + +int main(void) { - double product; - product = base * height; - return product / 2; + int i = 1, j = 2; + swap(i, j); + printf("i = %d, j = %d\n", i, j); + return 0; } -double triangle_area(double base, double height) + +void swap(int a, int b) { - double product; - product = base * height; - return product / 2; + int temp = a; + a = b; + b = temp; } ``` +Answer: +``` +i = 1, j = 2 +``` +Because function parameters are passed by value and not reference in C, modifications to `a` and `b` are limited to the scope of `swap`. \ No newline at end of file