Jerry C. answered 04/04/23
Gain Confidence with Math
I can describe what happens in memory, and from that, you should be able to diagram it.
The variables x,y, and p are assigned on the stack. x is initialized to 1.5, y to 3.4, and p is a pointer which is initialized to point at x. p2 is created on the stack, and the array it points to is dynamically created with the 'new' statement, from the heap memory.
In *p+= y, the value of y is added to x. Then p is changed to point to y. Then the value of y is doubled, via pointer p.
In the loop, the value of the p2 array is initialized, all elements to the same value. After that, the trouble begins: the pointer p2 is set to the value of another pointer. This means you've lost hold of the array, and you can't manipulate it or delete it. This is called a memory leak.
Then it tries to delete the stack variable p (after setting p2 = p, the 'delete p2' actually tries to delete whateve p is pointing to, in this case, y). This may cause the program to crash.