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 1 Question 15 Discussion

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

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

#include

using namespace std;

int op(int x, int y);

float op(int x, float y);

int main()

{

int i=1, j=2, k;

float f=0.3;

k = op(i, j);

cout<< k << "," << op(0, f);

return 0;

}

int op(int x, int y)

{

return x+y;

}

float op(int x, float y)

{

return x?y;

}

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

0/2000 characters
Helene
3 months ago
Definitely not B, that doesn't make sense.
upvoted 0 times
...
Claudio
3 months ago
I thought it would print 3,1!
upvoted 0 times
...
Nadine
3 months ago
Wait, how does it return 0 for op(0, f)?
upvoted 0 times
...
Trina
4 months ago
I agree, option C is correct!
upvoted 0 times
...
Theola
4 months ago
It prints: 3,0
upvoted 0 times
...
Gussie
4 months ago
I’m leaning towards option C, but I’m not entirely sure if the float function will actually return 0 or if it will print the float value directly.
upvoted 0 times
...
Tony
4 months ago
I practiced a similar question, and I feel like the second call to op should return 0.3, but I can't recall if it gets printed as is or if it gets converted.
upvoted 0 times
...
Theron
5 months ago
I think the first part will definitely return 3, but I'm confused about what happens with the float. Did we cover that it might return 0 if the condition is false?
upvoted 0 times
...
Beth
5 months ago
I remember something about function overloading, but I'm not sure how the float return type affects the output.
upvoted 0 times
...
Leota
5 months ago
I'm not entirely sure about the behavior of the second op() function. The "x?y" expression is throwing me off. I'll have to think this through carefully before selecting an answer.
upvoted 0 times
...
Lucina
5 months ago
This seems straightforward enough. The first op() function is called with the integer arguments, and the second op() function is called with the integer and float arguments. I'm pretty confident the answer is A.
upvoted 0 times
...
Helga
5 months ago
Okay, I think I've got it. The first op() function adds the two integer arguments, so k = op(i, j) will be 3. The second op() function returns the float argument, so op(0, f) will be 0.3. I'll go with option A.
upvoted 0 times
...
Tesha
5 months ago
Hmm, I'm a bit confused by the second op() function. What does the "x?y" expression mean? I'll have to look that up before I can confidently answer this.
upvoted 0 times
...
Dean
5 months ago
This looks like a tricky function overloading question. I'll need to carefully trace the code to figure out which version of the op() function is being called in each case.
upvoted 0 times
...
Aileen
5 months ago
I'm feeling pretty confident about this one. The details around IGMP SSM Mapping and the different IGMP versions seem straightforward to me. I'll carefully evaluate each option and select the one that is clearly wrong.
upvoted 0 times
...
Emelda
5 months ago
I'm a bit confused by the wording of this question. What exactly are the differences between these options? I'll need to review my notes to make sure I fully grasp the concepts before selecting an answer.
upvoted 0 times
...
Della
5 months ago
Okay, I think I've got a strategy for this. I'll focus on the keywords "add AP on AC" and see which option best addresses that.
upvoted 0 times
...
Willow
5 months ago
This seems straightforward enough. I'll probably go with option C and use the beforeMessage property to make sure I get all the messages for the month.
upvoted 0 times
...
Stefany
10 months ago
Ah, the old 'let's confuse the programmer with some weird function overloading' trick. I'm gonna have to go with B) It prints: 3,?0.3. The first op function is straightforward, but the second one is a real head-scratcher. Maybe the developer was trying to channel their inner Gandalf or something.
upvoted 0 times
Nadine
9 months ago
Yeah, it's like they wanted to add some mystery to the code. But B) It prints: 3,?0.3 makes sense.
upvoted 0 times
...
Lorrie
10 months ago
I think you're right, that second op function is definitely throwing a curveball.
upvoted 0 times
...
...
Yuette
10 months ago
Wow, this code is a real head-scratcher. I'm going to have to go with D) It prints: 0,0. The second op function is completely messed up, and I'm not even sure what it's supposed to be doing. Maybe the developer was trying to impress the interviewer with some fancy C++ tricks, but it just ended up being a disaster.
upvoted 0 times
Carrol
9 months ago
The code is definitely confusing. I also think it prints: 3,0. The second op function is not functioning as expected.
upvoted 0 times
...
Willis
10 months ago
Yeah, the second op function is a mess. It's returning 0 no matter what. So, the output will be: 3,0.
upvoted 0 times
...
Melodie
10 months ago
I agree, the second op function is definitely not correct. It should have been returning y instead of x?y. So, it prints: 3,0.
upvoted 0 times
...
Felix
10 months ago
I think it prints: 3,0. The first op function adds the two integers, and the second op function returns 0 for any value of x.
upvoted 0 times
...
...
Coral
10 months ago
Hmm, this is a tricky one. I'm going to go with C) It prints: 3,0. The first op function is correct, but the second one is clearly broken. I wonder if the developer was trying to do some kind of ternary operation, but it's not working as expected.
upvoted 0 times
...
Ashton
11 months ago
This code has a problem with the second op function. The return statement 'x?y' is not valid C++ syntax. I think the correct answer is B) It prints: 3,?0.3.
upvoted 0 times
Vincent
10 months ago
User 2
upvoted 0 times
...
Elly
10 months ago
User 1
upvoted 0 times
...
...
Evette
11 months ago
The output should be 3,0.3. The first call to op(i, j) will return the sum of i and j, which is 3. The second call to op(0, f) will return 0.3, since the first parameter is an integer and the second parameter is a float.
upvoted 0 times
...
Vivienne
11 months ago
But the second function returns x?y, which means it will return 0.3 if x is not 0. So, I still think it's A)
upvoted 0 times
...
Cory
11 months ago
I disagree, I believe the answer is B) It prints: 3,?0.3
upvoted 0 times
...
Vivienne
11 months ago
I think the answer is A) It prints: 3,1
upvoted 0 times
...

Save Cancel