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