Why we use “&(*” statement when double pointer to struct is an argument of a function?

前端 未结 3 686
萌比男神i
萌比男神i 2021-01-29 08:09
void instert(NODE**root, int value)
{
    ...
    insert(&(*root)->left,value);
    ...
}

void search(NODE*root, int value)
{
    ...
    search(root->left, v         


        
3条回答
  •  悲&欢浪女
    2021-01-29 08:57

    The expression:

    *root->left
    

    Is equivalent to:

    *(root->left)
    

    Due to operator precedence.

    So you need:

    (*root)->left
    

    If you want the left member that *root points to.

    And then:

    &(*root)->left
    

    Is the pointer to the left member of *root, which is then of type NODE **, what the insert function requires.

提交回复
热议问题