Having trouble understanding linked list/pointers

This is a function that deletes the first element in the linked list

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void List::removeStart()
{
    if(length == 0)
    {
        cout << "removeStart : List is empty, no data to remove." << endl;
        return;
    }
    else if(length == 1)
    {
        delete start;
        start = stop = NULL;
        length = 0;
    }
    else
    {
        Node* temp = start;
        start = start->next;
        delete temp;
        length--;
    }
}

start is a node pointer that points to the first element.
What I'm not understanding is how does deleting a pointer to a node delete the node itself? From what I understand about pointers, "start" just stores the address of the node. How does deleting the address delete the node itself?
Last edited on
http://en.cppreference.com/w/cpp/language/delete
The pointer refers to an object previously created by a new-expression. Writing delete p destroys the object *p and releases the memory allocated for it, and does nothing to p.
is *p the pointer dereferenced?

this makes a lot more sense now, thanks!
Last edited on
is *p the pointer dereferenced?
Yes! delete p destroys the pointed-to object, but leaves the pointer alone.
Topic archived. No new replies allowed.