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 CPA-21-02 Exam - Topic 6 Question 53 Discussion

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

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

#include

using namespace std;

void fun(int &i);

int main()

{

int i=2;

fun(i);

cout<

return 0;

}

void fun(int &i)

{

i+=2;

}

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

0/2000 characters
Quentin
2 days ago
I'm not entirely sure, but I remember something about references in C++. Could it be that it prints 2 instead?
upvoted 0 times
...
Mariann
7 days ago
I think the function modifies the value of `i` since it's passed by reference, so it should print 4.
upvoted 0 times
...

Save Cancel