What happens if you try to compile and run this program?
#include
int f1(int n) {
return n = n * n;
}
int f2(int n) {
return n = f1(n) * f1(n);
}
int main(int argc, char ** argv) {
printf ("%d \n", f2(1));
return 0;
}
-
Select the correct answer:
In the f1 function, n = n * n; squares the input n and assigns the result back to n.
In the f2 function, f1(n) * f1(n) calls f1 twice with the input n and multiplies the results.
In the main function, printf('%d n', f2(1)); prints the result of f2(1).
Let's calculate:
1. f1(1) returns 1 * 1 = 1.
2. f2(1) calls f1 twice with the input 1, so it's f1(1) * f1(1) = 1 * 1 * 1 * 1 = 1.
Currently there are no comments in this discussion, be the first to comment!