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
13 comments · newest first
JA
Jamika
8 hours ago
It definitely won't print 1 or 0.
EV
Evangelina
5 days ago
I feel confused about pointers though.
KA
Kati
11 days ago
Yeah, because *i becomes 2*2.
DY
Dylan
16 days ago
I think it prints 4.
LI
Lino
21 days ago
This seems off, are you sure about that?
AR
Arlette
26 days ago
I thought it would print 10, but I guess not!
DA
Dan
1 month ago
Wait, how does it even get to 4?
VI
Virgie
1 month ago
Totally agree, it's definitely 4!
SH
Shaniqua
1 month ago
It prints: 4
ER
Eric
2 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
2 months ago
Wait, does the `*i = *i * *i;` mean it squares the value? If so, then it should print 4, right?
BR
Brock
2 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
2 months ago
I think the function modifies the value of `i`, but I'm not sure what the final output will be.