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:
Suggested Answer: E
Get Premium CLA-11-03 Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
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.
4 comments · newest first
VI
Vincent
3 days ago
I believe the output should be 4 because f1(1) returns 1, and then f2 calls f1 twice, but I could be wrong.
DO
Dorathy
8 days ago
I’m a bit confused about the return values. Does f1 return the squared value or just the modified n?
RA
Rashad
13 days ago
I remember a similar question where we had to track variable changes. I feel like f2 will end up calling f1 twice.
SH
Shawana
18 days ago
I think the function f1 modifies n and returns it, but I'm not sure how that affects f2.