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 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:

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
...
Yuette
2 days 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
...
Coral
5 days 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
9 days 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
...
Evette
12 days 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
13 days 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
16 days ago
I disagree, I believe the answer is B) It prints: 3,?0.3
upvoted 0 times
...
Vivienne
21 days ago
I think the answer is A) It prints: 3,1
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