If you set p=3D0, you are pointing nowhere, and I found that weird. But
it actualy makes sense, it=B4s better to have the program crash
right away if something tries to write on it, than to have it write
fine
on some dark zone of heapland which you will never be able to reach
again.
Reduces debugging time.
Thanks folks.
On Apr 11, 4:56 pm, "Default User"
> Rafael Anschau wrote:
> > I read that you should assign null (0) to all pointers that you call
> > delete on.
>
> Controversial, at best. I never do that.
>
> > Does that mean:
>
> > *p=3D0(set the value pointed to to 0).
>
> This would undefined behavior, as you would be deferencing a pointer to
> deleted storage.
>
> > or
>
> > p=3D0(set the address held to zero).
>
> > The last one is awkward for none would want a pointer pointing
> > to address zero(even though it compiles fine, you can?t assign
> > anything to it).
>
> You seem confused. You can't dereference it, but you couldn't before.
> You can certainly assign something to p. That is:
>
> delete[] p;
> p =3D 0;
> p =3D new int[20]; // p is int* for this example
>
> Is perfectly fine.
>
> > I find the first still awkward because you are assigning a value to
> > place
> > you no longer use.
>
> Far more than awkward, it's undefined behavior. You must not do that.
>
> Brian