Is it right way to assign deleted pointer?

I want to assign a pointer to deleted pointer like this

int *p = new int;
int *q = new int;
.
(some code)
.
delete p;

p=q;

is it right??
Term
deleted pointer

is misleading.

You don't "delete pointer p". You do delete an int object, whose address is known by pointer p.

After delete p; the p still has that same address, but the address does not contain valid object. Invalid address.

The p is a pointer. Pointer stores an address. You can store any address in the pointer.

p = q; simply copies value of q into p. It is no different from:
1
2
3
4
double foo;
double bar = 3.14;

foo = bar; // copy value of bar into foo 

Topic archived. No new replies allowed.