Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 0d 12h 49m 23s Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

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

Stefany
1 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
11 days 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
30 days ago
I think you're right, that second op function is definitely throwing a curveball.
upvoted 0 times
...
...
Yuette
1 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
22 hours 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
24 days 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
25 days 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
1 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
1 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
2 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
30 days ago
User 2
upvoted 0 times
...
Elly
1 months ago
User 1
upvoted 0 times
...
...
Evette
2 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
2 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
2 months ago
I disagree, I believe the answer is B) It prints: 3,?0.3
upvoted 0 times
...
Vivienne
2 months ago
I think the answer is A) It prints: 3,1
upvoted 0 times
...

Save Cancel
a