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
2 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
4 days ago
It prints: 2 8
upvoted 0 times
...
Elenora
12 days ago
The default parameter is 2, so it multiplies the values.
upvoted 0 times
...
Elenora
1 months ago
No, the function is called 'mul' not 'divide'.
upvoted 0 times
...
...
Ronna
2 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
1 months ago
Yes, the default parameter kicks in for the first call to mul.
upvoted 0 times
...
Glory
2 months ago
I think you're right, it should print 2 and 8.
upvoted 0 times
...
...
Truman
2 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
2 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
1 months ago
When you add them up, it prints 8.
upvoted 0 times
...
Jose
1 months ago
So 'mul(1)' returns 2 and 'mul(2,4)' returns 8.
upvoted 0 times
...
Raul
2 months ago
Yes, that's correct! The default parameter is 2 in the 'mul' function.
upvoted 0 times
...
Jani
2 months ago
I think the answer is C) It prints: 8
upvoted 0 times
...
...
Fatima
2 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
2 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
3 months ago
I disagree, I believe the answer is C) It prints: 8.
upvoted 0 times
...
Fairy
3 months ago
I think the answer is B) It prints: 28.
upvoted 0 times
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77