C++ Institute CPA-21-02 Exam - Topic 8 Question 45 Discussion
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
A) It will print: 100
B) It will print: 101
C) It will print: 10
D) It will print: 1
C++ Institute CPA-21-02 Exam - Topic 8 Question 45 Discussion
Actual exam question for
C++ Institute's
CPA-21-02 exam
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.
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.
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.
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.
Shenika
2 months agoFreeman
3 months agoXochitl
3 months agoTracie
3 months agoGenevieve
4 months agoBuck
4 months agoDeonna
4 months agoLelia
4 months agoAliza
4 months agoCelestina
4 months agoBenedict
5 months agoLetha
5 months agoRebbeca
5 months agoKyoko
5 months agoCordell
6 months agoVince
6 months agoLoreta
6 months agoBarbra
6 months agoBuck
7 months agoMadalyn
7 months agoCasie
7 months agoArleen
7 months agoNoelia
7 months agoCarmela
2 months agoVal
2 months agoKaran
2 months agoAlita
5 months agoJanella
5 months ago