class Node{
int a;
Node* next;
Node():a(20),next(NULL){};
};
int main()
{
Node* p = new Node;
p->next = new Node;
Node* q = p->next;
**delete q; (or delete p->next;)**
cout << q << endl; // always changed to "0000 8123"
cout << &q->a << endl; // 0000 8123
cout << &q->next << endl; // 0000 8127
cout << q->a << q->next << endl; // error! why it is ok to access their address and no to access their value?
cout << p->next << endl; // p->next no change , why ?
cout << p->next->a << endl; // changed to "DDDD DDDD"
cout << p->next->next << endl; // changed to "-5726 2307"
return 0;
}
I know pointer p and q are on the stack, objects are on the heap.
delete q;
q was changed to pointer an object in stack;
delete p->next;
why was the value of p->next not changed?
What is the specific procedure of delete?