-3
#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)Why do we use a pointer to pointer. Can it be explained with an example. 2)How to do insertion into a doubly linked list? HElp me and please explain how to print

assylias
  • 321,522
  • 82
  • 660
  • 783
Rahul Reddy
  • 12,613
  • 10
  • 22
  • 21

2 Answers2

2

Often a pointer to pointer is used when you want to pass to a function a pointer that the function can change.

Claudio
  • 10,614
  • 4
  • 31
  • 71
1

Pointer to pointer or double pointer are variables whose possible values ​​are memory addresses of other pointer variables.

You have a good answer here, I think he can explain it better than me.

Also you can check this link.

Community
  • 1
  • 1
  • Note that link only answers are discouraged on SO, especially link-only to other SO answers. – mvp Jun 04 '13 at 07:13