vault backup: 2024-10-12 21:02:02

This commit is contained in:
zleyyij 2024-10-12 21:02:02 -06:00
parent 11026292fd
commit 1404a57929

View File

@ -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? > 9. What will be the output of the following program?
```c ```c
double triangle_area(double base, double height) #include <stdio.h>
void swap (int a, int b);
int main(void)
{ {
double product; int i = 1, j = 2;
product = base * height; swap(i, j);
return product / 2; 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; int temp = a;
product = base * height; a = b;
return product / 2; 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`.