New Year Sale 2026! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CPA-21-02 Exam - 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:

0/2000 characters
Melinda
3 months ago
The default parameter really changes things!
upvoted 0 times
...
Brandon
4 months ago
I thought it would be 8, not 6.
upvoted 0 times
...
Shalon
4 months ago
Wait, how does it get 6?
upvoted 0 times
...
Jean
4 months ago
Totally agree, that's the right output!
upvoted 0 times
...
Billy
4 months ago
It prints: 6
upvoted 0 times
...
Percy
5 months ago
I feel like the output should be 6 because mul(1) gives 2 and mul(2, 4) gives 8, but I might be mixing things up.
upvoted 0 times
...
Tracey
5 months ago
I practiced a similar question, and I think the total output would be 2 + 8, which makes 10, but that’s not an option here.
upvoted 0 times
...
Nada
5 months ago
I'm not entirely sure, but I think the second call mul(2, 4) would multiply 2 by 4, giving 8.
upvoted 0 times
...
Effie
5 months ago
I remember that default parameters can be tricky. I think mul(1) would use the default value of 2, so that would be 1 * 2.
upvoted 0 times
...
Luz
5 months ago
Wait, I'm not sure about that. Let me double-check the logic here. I don't want to make any assumptions.
upvoted 0 times
...
Tamekia
5 months ago
I'm feeling pretty confident about this one. The output should be 2 and 8, for a total of 10.
upvoted 0 times
...
Marshall
5 months ago
Okay, I think I've got this. The first call to mul() will use the default parameter of 2, and the second call will use the explicit parameter of 4.
upvoted 0 times
...
Tonja
5 months ago
Hmm, I'm a bit confused by the default parameter in the function. I'll need to make sure I understand how that works.
upvoted 0 times
...
Norah
5 months ago
This looks like a tricky one. I'll need to carefully read through the code and think through the function calls.
upvoted 0 times
...
Britt
5 months ago
Hmm, I'm a bit unsure about this one. I know the SLA is important, but I'm not totally clear on what the auditor's main goal should be. I'll need to review the details of the question and think through the different options carefully.
upvoted 0 times
...
Jamal
11 months 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
Elenora
9 months ago
It prints: 2 8
upvoted 0 times
...
Elenora
9 months ago
The default parameter is 2, so it multiplies the values.
upvoted 0 times
...
Elenora
10 months ago
No, the function is called 'mul' not 'divide'.
upvoted 0 times
...
...
Ronna
11 months 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
Bambi
10 months ago
Yes, the default parameter kicks in for the first call to mul.
upvoted 0 times
...
Glory
10 months ago
I think you're right, it should print 2 and 8.
upvoted 0 times
...
...
Truman
11 months 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
11 months 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
Roslyn
10 months ago
When you add them up, it prints 8.
upvoted 0 times
...
Jose
10 months ago
So 'mul(1)' returns 2 and 'mul(2,4)' returns 8.
upvoted 0 times
...
Raul
11 months ago
Yes, that's correct! The default parameter is 2 in the 'mul' function.
upvoted 0 times
...
Jani
11 months ago
I think the answer is C) It prints: 8
upvoted 0 times
...
...
Fatima
11 months 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
11 months 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
11 months ago
I disagree, I believe the answer is C) It prints: 8.
upvoted 0 times
...
Fairy
11 months ago
I think the answer is B) It prints: 28.
upvoted 0 times
...

Save Cancel