Hi,
Qt Code:
int* a = new int; int** b = &a; delete a; a = new int;To copy to clipboard, switch view to plain text mode
When creating the new "int" pointer "a", can "**b" be accessed or it will access to a bad memory data?
Thanks,
Hi,
Qt Code:
int* a = new int; int** b = &a; delete a; a = new int;To copy to clipboard, switch view to plain text mode
When creating the new "int" pointer "a", can "**b" be accessed or it will access to a bad memory data?
Thanks,
Òscar Llarch i Galán
b should work fine!
(address=XXX, pointsTo=XXX where XXX are memory addresses)
a: address=1 pointsTo=10
b: address=2 pointsTo=1 (-> which points to 10)
a: address=1 pointsTo=NULL
(b: address=2 pointsTo=1 (-> which points to NULL))
a: address=1 pointsTo=11
b: address=2 pointsTo=1 (-> which points to 11)
Hi,
Thanks,
It is what I was expecting.
Òscar Llarch i Galán
A pointer just (a the name says) points to a piece of memory.
When you free that memory all accesses to it become invalid, both 'direct' ones (via the freed pointer) and also all other ways you manage to access the address of the freed memory.
So in your example, you may neither access *a or **b.
(The pointers themselves are valid, but the memory finally pointed to, is not.)
Bookmarks