I am reading Learning a New Programming Language: C++ for Java Programmers here, and there is an example on pointers that reads:
Never dereference a dangling pointer (a pointer to a location that was pointed to by another pointer that has been deleted):
int *p, *q;
p = new int;
q = p; // p and q point to the same location
delete q; // now p is a dangling pointer
*p = 3; // bad!
However, if I copy this code into a main function and add the following cout:
cout << p << " " << *p << endl;
I get the output:
0000022DC3DD0EF0 3
Which seems valid to me, I get the pointer and then the deref'd value.
Is this a typo in the webpage, or is the above code bad practice?