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 Exam CPA-21-02 Topic 5 Question 25 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 25
Topic #: 5
[All CPA-21-02 Questions]

What happens when you attempt to compile and run the following code?

#include

using namespace std;

int mul (int a, int b=2)

{

int r;

r=a*b;

return (r);

}

int main ()

{

cout << mul(1) << mul(2,4);

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: A

Contribute your Thoughts:

Jamal
14 days ago
Hmm, let's see... if the default parameter is 2, does that mean the function is called 'mul'? I bet the real answer is 'divide'! *wink wink*
upvoted 0 times
...
Ronna
16 days ago
Aha, I know this one! The default parameter in 'mul' is 2, so 'mul(1)' will give us 2. And 'mul(2,4)' will give us 8. Therefore, the answer is A) It prints: 2. Easy peasy!
upvoted 0 times
Glory
3 days ago
I think you're right, it should print 2 and 8.
upvoted 0 times
...
...
Truman
21 days ago
Wait, wait, wait... I think I got this. The default parameter in 'mul' is 2, so 'mul(1)' will give us 2. And 'mul(2,4)' will give us 8. Putting them together, the answer must be B) It prints: 28. Nailed it!
upvoted 0 times
...
Refugia
22 days ago
This is easy! The default parameter in the 'mul' function is 2, so 'mul(1)' will return 2. Then 'mul(2,4)' will return 8. Add them up, and the answer is C) It prints: 8.
upvoted 0 times
Raul
9 days ago
Yes, that's correct! The default parameter is 2 in the 'mul' function.
upvoted 0 times
...
Jani
11 days ago
I think the answer is C) It prints: 8
upvoted 0 times
...
...
Fatima
23 days ago
Hmm, let's see... if the default value for the second parameter in the 'mul' function is 2, then calling 'mul(1)' should give us 2. And 'mul(2,4)' should give us 8. So the answer must be D) It prints: 6.
upvoted 0 times
...
Fairy
29 days ago
But if you look at the code, when mul(1) is called, it uses the default value of b which is 2, so it should be 1*2=2. And when mul(2,4) is called, it should be 2*4=8. So the answer should be B) It prints: 28.
upvoted 0 times
...
Merri
1 months ago
I disagree, I believe the answer is C) It prints: 8.
upvoted 0 times
...
Fairy
1 months ago
I think the answer is B) It prints: 28.
upvoted 0 times
...

Save Cancel