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 CPP Exam - Topic 3 Question 22 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 22
Topic #: 3
[All CPP Questions]

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

#include

using namespace std;

template

void f(A &a)

{

cout<<1<

}

void f(int &a)

{

cout<<2<

}

int main()

{

int a = 1;

f(a);

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

0/2000 characters
Louis
3 months ago
Compilation error? That sounds weird, but I guess anything's possible!
upvoted 0 times
...
Altha
3 months ago
Wait, are you sure? I thought templates would take precedence.
upvoted 0 times
...
Heike
4 months ago
Definitely outputs 2, no doubt about it!
upvoted 0 times
...
Jennie
4 months ago
I think it should show 1, right?
upvoted 0 times
...
Ellen
4 months ago
The program displays: 2
upvoted 0 times
...
Leota
4 months ago
Okay, let me walk through this. There's a template function `f(A &a)` and a non-template function `f(int &a)`. When we call `f(a)`, the non-template function should be the better match, so the output should be 2.
upvoted 0 times
...
Jannette
4 months ago
Ah, I see what's going on! The more specific `f(int &a)` function will be called, so the output should be 2. I'm confident I can solve this one.
upvoted 0 times
...
Jonelle
5 months ago
Hmm, I'm a bit confused. The code seems straightforward, but I'm not sure which function will be called. I'll have to think this through step-by-step.
upvoted 0 times
...
Amalia
5 months ago
This looks like a tricky template function question. I'll need to carefully consider the function overloading rules and how they apply here.
upvoted 0 times
...
Theron
5 months ago
Hmm, I'm a bit unsure about this one. The question mentions a "unique solution" for each question, so I'm not sure if this is the only correct answer or if there might be other ways to approach it.
upvoted 0 times
...
Maryann
5 months ago
I'm pretty confident about this one. The server is removed from the All Servers group, and scheduled backups for the server will be discontinued. Those are the two results I'm going with.
upvoted 0 times
...

Save Cancel