vault backup: 2024-10-12 21:02:02
This commit is contained in:
parent
11026292fd
commit
1404a57929
@ -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`.
|
Loading…
Reference in New Issue
Block a user