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?
```c
double triangle_area(double base, double height)
#include <stdio.h>
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`.