BLACK FRIDAY SALE – Unlock Up to 25% OFF on All Exam Prep! - 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

Posted by Darci on May 02, 2026 at 01:50 AM

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;

}

Suggested Answer: C

Get Premium CPA-21-02 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
25 comments · newest first
JA
Janey 1 month ago
Good to clarify how references work!
GE
Gerald 2 months ago
D is way off too, just a distraction.
RI
Rima 2 months ago
Definitely not A or B, those are wrong.
MA
Maira 2 months ago
I was confused at first, but it makes sense now.
CA
Carmen 2 months ago
So, option C is correct!
FE
Felicitas 2 months ago
I agree, the reference changes the value.
JA
Janna 3 months ago
Yeah, because fun modifies i directly.
LE
Lenna 3 months ago
I think it prints 4.
TI
Timmy 3 months ago
Same here, references are powerful in C++.
DE
Desmond 3 months ago
I feel confident about this one, it's clear.
YO
Yoko 3 months ago
I thought it would print 2, but I see the reference works.
DO
Dorathy 3 months ago
I was confused at first, but it makes sense now.
SO
Sophia 4 months ago
Definitely 4, i starts at 2, then adds 2.
GI
Gilma 4 months ago
I agree, the reference changes the value.
KE
Kenny 4 months ago
Yeah, because fun modifies i directly.
CA
Caitlin 4 months ago
I think it prints 4.
DI
Dierdre 4 months ago
I thought it would print 0 for some reason!
RO
Rory 4 months ago
Definitely C, the reference changes the original.
PA
Pamella 5 months ago
Wait, are you sure it doesn't print 2?
YU
Yuki 5 months ago
Totally agree, it modifies the value!
MI
Mitzie 5 months ago
It prints: 4
AL
Alverta 5 months ago
I’m confused about the output. I thought it might print 0, but now I’m leaning towards 4 since the function adds 2 to `i`.
EL
Elroy 7 months ago
I practiced a similar question where passing by reference changed the variable's value. I believe it should print 4.
QU
Quentin 7 months ago
I'm not entirely sure, but I remember something about references in C++. Could it be that it prints 2 instead?
MA
Mariann 7 months ago
I think the function modifies the value of `i` since it's passed by reference, so it should print 4.
0/2000 characters

Save Cancel