c - 为什么我们使用指向指针的指针

标签 c pointers linked-list

#include <stdio.h>
#include <stdlib.h>

struct llnode {
    int data;
 struct    llnode *next;
};
void insert (struct llnode **head, int data);


int
main () {
    struct llnode *head;
    head = NULL;
    printf("starting\n");
    insert(&head, 4);



    return 0;
}

void
insert (**struct llnode **head**, int data) {--> why do we use a pointer to a pointer 
    printf("insert %0d\n", data);

struct    llnode *l = malloc(sizeof(struct llnode));
    l->data = data;
    l->next = NULL;

    if (*head == NULL) {
        *head = l;
    } else {
struct        llnode *tmp = *head;
        while (tmp->next != NULL) {
            tmp = tmp->next;
        }
        tmp->next = l;
    }
}

1)为什么要使用指针到指针。能否用一个例子来解释一下。 2)如何向双向链表进行插入操作? 请帮助我并解释如何打印

最佳答案

当您想要将函数可以更改的指针传递给函数时,通常会使用指向指针的指针。

关于c - 为什么我们使用指向指针的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16911525/

相关文章:

java - JNI GetMethodID 不适用于内部类的构造函数

c - 结构体和指针

c - 如果不用指针实现链表会发生什么?

linked-list - 单链表面试题

c - gcc undefined reference `fopen_s'

c++ - C 编程通过每次 8 位输入将 64 位值存储在寄存器中

c - 在 C 中释放 NULL 指针是一种好习惯吗?

delphi - 如何将指向类型的指针视为指向该类型数组的指针

c - 如何在C中将一个数组的数据复制到另一个数组?

c# - 在 LinkedListNode<T> 上添加扩展方法