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 59 Discussion

Posted by Ardella on Aug 16, 2026 at 03:13 PM

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

#include

using namespace std;

void fun(int*);

int main()

{

int i=2;

fun(&i);

cout<

return 0;

}

void fun(int *i)

{

*i = *i**i;

}

Suggested Answer: B

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
21 comments · newest first
AR
Art 4 days ago
Definitely B. The multiplication changes the value.
IL
Iluminada 9 days ago
I was confused at first, but it makes sense now.
RO
Roosevelt 15 days ago
I feel confident about this one.
FR
Freeman 20 days ago
So, option B is correct.
LO
Loise 25 days ago
Yeah, because *i becomes 2 * 2.
IR
Ira 1 month ago
I think it prints 4.
FL
Florinda 1 month ago
I hope I get this right in the exam!
JU
Justine 1 month ago
I agree, 4 makes sense with the multiplication.
JA
Jamika 2 months ago
It definitely won't print 1 or 0.
EV
Evangelina 2 months ago
I feel confused about pointers though.
KA
Kati 2 months ago
Yeah, because *i becomes 2*2.
DY
Dylan 2 months ago
I think it prints 4.
LI
Lino 2 months ago
This seems off, are you sure about that?
AR
Arlette 2 months ago
I thought it would print 10, but I guess not!
DA
Dan 3 months ago
Wait, how does it even get to 4?
VI
Virgie 3 months ago
Totally agree, it's definitely 4!
SH
Shaniqua 3 months ago
It prints: 4
ER
Eric 3 months ago
I'm confused about the order of operations here. Could it be that it prints 10? I need to double-check how the multiplication works with pointers.
RO
Rory 3 months ago
Wait, does the `*i = *i * *i;` mean it squares the value? If so, then it should print 4, right?
BR
Brock 3 months ago
I remember something similar where a pointer was used to change a variable's value. I think it might print 4 because of the multiplication.
LA
Latricia 4 months ago
I think the function modifies the value of `i`, but I'm not sure what the final output will be.
0/2000 characters

Save Cancel