I saw this piece of c++ code under the topic of dangling pointer on the internet and tried executing it. This might not be pleasant to look at but here goes...
int *x, *y, *z;
x = new int;
*x = 3;
y = x;
delete x;
x = NULL;
z = new int;
*z = 5;
*y = 2;
When I print *z, it always turns out to be equal to the value of *y(as specified in the last line of code), 2 in this case but how is this possible if I specifically did *z = 5 in the second last line itself.