fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct list {
  5. int key;
  6. struct list *next;
  7. };
  8.  
  9. void append(struct list **l1, struct list l2)
  10. {
  11. *l1 = malloc(sizeof *l1);
  12. **l1 = l2;
  13. (*l1)->next = NULL;
  14. }
  15.  
  16. int main(void)
  17. {
  18. struct list *l1, l2 = { 42, NULL }, l3 = { 24, NULL };
  19.  
  20. append(&l1, l2);
  21. append(&l1->next, l3);
  22.  
  23. for (struct list *p = l1; p != NULL; p = p->next)
  24. printf("%d\n", p->key);
  25.  
  26. free(l1->next);
  27. free(l1);
  28. }
  29.  
Success #stdin #stdout 0.01s 1852KB
stdin
Standard input is empty
stdout
42
24