New Year Sale 2026! 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

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

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;

}

Show Suggested Answer Hide Answer
Suggested Answer: A

Contribute your Thoughts:

0/2000 characters
Xochitl
1 day ago
Yeah, I agree. The input is 10, so 10*10 is 100.
upvoted 0 times
...
Tracie
7 days ago
Just to clarify, it returns the square of 10, right?
upvoted 0 times
...
Genevieve
12 days ago
Nah, it's definitely not 101 or 10.
upvoted 0 times
...
Buck
17 days ago
Wait, are you sure? I thought it might print something else.
upvoted 0 times
...
Deonna
22 days ago
Totally agree, it's definitely 100!
upvoted 0 times
...
Lelia
27 days ago
It will print: 100
upvoted 0 times
...
Aliza
1 month ago
A is the correct answer. This is a simple program that demonstrates the use of dynamic memory allocation and function calls.
upvoted 0 times
...
Celestina
1 month 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!
upvoted 0 times
...
Benedict
1 month 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.
upvoted 0 times
...
Letha
2 months ago
Definitely A. The code is straightforward, and the output will be the square of 10, which is 100.
upvoted 0 times
...
Rebbeca
2 months ago
The answer is A. The function fun() will return the square of the value passed to it, which is 10.
upvoted 0 times
...
Kyoko
2 months ago
I practiced a similar question where a function returned the square of a number. I feel like the answer should be 100.
upvoted 0 times
...
Cordell
2 months ago
I'm not entirely sure, but I remember something about dereferencing pointers. Could it be that it prints 10 instead?
upvoted 0 times
...
Vince
3 months ago
I think it will print: 100. The function squares the input.
upvoted 0 times
...
Loreta
3 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.
upvoted 0 times
...
Barbra
3 months ago
I think the code will print 100 because the function squares the value of *x, which is 10.
upvoted 0 times
...
Buck
3 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.
upvoted 0 times
...
Madalyn
4 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.
upvoted 0 times
...
Casie
4 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.
upvoted 0 times
...
Arleen
4 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.
upvoted 0 times
...
Noelia
4 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.
upvoted 0 times
Alita
2 months ago
Yeah, the function squares the value.
upvoted 0 times
...
Janella
2 months ago
I agree, it should print 100.
upvoted 0 times
...
...

Save Cancel