DMA Issue

Question: From the perspective of dynamic memory management, clearly describe the issue with the following code. Also suggest a way to fix that issue.

Please help me!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

class A {
public:
 int *p;
 A() {
 p = new int[5];
 for(int i = 0; i < 5; i++)
 p[i] = 0;
 }
 ~A(){ delete [] p; p = NULL;}
};
void display(A obj) {
 for(int i = 0; i < 5; i++)
 cout<<"value is"<<obj.p[i]<<endl;
 }
int main() {
 A a1; display(a1);
 display(a1);
}
What happens when you pass a1 to the display function?
Topic archived. No new replies allowed.