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:

Truman
3 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
4 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
...
Fatima
5 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
11 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
13 days ago
I disagree, I believe the answer is C) It prints: 8.
upvoted 0 times
...
Fairy
14 days ago
I think the answer is B) It prints: 28.
upvoted 0 times
...

Save Cancel