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 8 Question 45 Discussion

Posted by Han on Oct 30, 2025 at 03:16 PM

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

#include

#include

using namespace std;

int fun(int);

int main()

{

int *x = new int;

*x=10;

cout << fun(*x);

return 0;

}

int fun(int i)

{

return i*i;

}

Suggested Answer: A

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
28 comments · newest first
SH
Shenika 7 months ago
No way! It definitely returns 100. The logic is clear in the code.
FR
Freeman 7 months ago
I'm not so sure. What if it prints 10? The function just returns the input.
XO
Xochitl 8 months ago
Yeah, I agree. The input is 10, so 10*10 is 100.
TR
Tracie 8 months ago
Just to clarify, it returns the square of 10, right?
GE
Genevieve 8 months ago
Nah, it's definitely not 101 or 10.
BU
Buck 8 months ago
Wait, are you sure? I thought it might print something else.
DE
Deonna 8 months ago
Totally agree, it's definitely 100!
LE
Lelia 8 months ago
It will print: 100
AL
Aliza 9 months ago
A is the correct answer. This is a simple program that demonstrates the use of dynamic memory allocation and function calls.
CE
Celestina 9 months ago
Haha, I bet the answer is B. The code is clearly broken, and it will print some random number like 101. Programmers can be so creative!
BE
Benedict 9 months ago
I think the answer is C. The code is printing the value of x, which is 10, not the result of the function call.
LE
Letha 9 months ago
Definitely A. The code is straightforward, and the output will be the square of 10, which is 100.
RE
Rebbeca 9 months ago
The answer is A. The function fun() will return the square of the value passed to it, which is 10.
KY
Kyoko 10 months ago
I practiced a similar question where a function returned the square of a number. I feel like the answer should be 100.
CO
Cordell 10 months ago
I'm not entirely sure, but I remember something about dereferencing pointers. Could it be that it prints 10 instead?
VI
Vince 10 months ago
I think it will print: 100. The function squares the input.
LO
Loreta 11 months ago
I’m confused about the memory allocation part. Does it affect the output? I hope it still prints 100 like I think it does.
BA
Barbra 11 months ago
I think the code will print 100 because the function squares the value of *x, which is 10.
BU
Buck 11 months ago
I think the key here is understanding how dynamic memory allocation and the fun() function work. If we can grasp those concepts, the answer should be straightforward.
MA
Madalyn 11 months ago
I'm pretty confident the answer is A. The fun() function simply squares the input, and since we pass 10 to it, the output should be 100.
CA
Casie 11 months ago
Hmm, I'm not sure. I'd need to carefully step through the code to understand exactly what's happening. The dynamic allocation and lack of deallocation is making me hesitant.
AR
Arleen 12 months ago
I'm a bit confused. Doesn't the code have a memory leak since it doesn't delete the dynamically allocated integer? I'm not sure if that would affect the output.
NO
Noelia 12 months ago
I think the answer is A. The code dynamically allocates an integer, sets its value to 10, and then passes that value to the fun() function, which returns the square of the input.
CA
Carmela 6 months ago
↳ replying to Noelia
Can't wait to see the output!
VA
Val 6 months ago
↳ replying to Noelia
I was confused at first, but it makes sense now.
KA
Karan 7 months ago
↳ replying to Noelia
Definitely A! The logic is clear.
AL
Alita 10 months ago
↳ replying to Noelia
Yeah, the function squares the value.
JA
Janella 10 months ago
↳ replying to Noelia
I agree, it should print 100.
0/2000 characters

Save Cancel