2

Is there a way to point to the pointer variable instead of it's address space so that it can be changed to NULL. Something like this. Apologies for the poor question I can't think of a better way of expressing what I'm trying to do. Thanks.

typedef struct Node
{
    int val;
    struct Node *r;
    struct Node *l;
} Node;

Node* del(Node *N, int v)
{
    Node *n = N;
    Node **p = NULL;

    while (n != NULL)
    {
        if (something)
        {
            p = n.r;
            n = n->r;
        }
        else {
            p = n.l;
            n = n->l;
        }

        free(n);
        *p = NULL;
    }
}

1 Answer 1

3

You can use & on a pointer just like on any other variable. In your case, it looks like you might want to change del to:

Node *del(Node **N, int v)

And then call it like:

x = del(&someNode, 12);
Sign up to request clarification or add additional context in comments.

2 Comments

And dereference with an additional *.
and use all the other regular pointer ops for the most part. Nested pointers are a very... fun thing :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.