Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CLA-11-03 Exam - Topic 3 Question 1 Discussion

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:
E) The program outputs 1
A) The program outputs 8
B) The program outputs 2
C) Execution fails
D) The program outputs 4

C++ Institute CLA-11-03 Exam - Topic 3 Question 1 Discussion

Actual exam question for C++ Institute's CLA-11-03 exam
Question #: 1
Topic #: 3
[All CLA-11-03 Questions]

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:

Show Suggested Answer Hide Answer
Suggested Answer: E

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.


Contribute your Thoughts:

0/2000 characters

Currently there are no comments in this discussion, be the first to comment!


Save Cancel