fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct list {
  5. int key;
  6. struct list *next;
  7. };
  8.  
  9. struct list *append(struct list **l, int k)
  10. {
  11. *l = malloc(sizeof *l);
  12. (*l)->key = k;
  13. return *l;
  14. }
  15.  
  16. void print(struct list *node)
  17. {
  18. while(node)
  19. {
  20. printf("%d\n", node->key);
  21. node = node->next;
  22. }
  23. }
  24.  
  25. int main(void)
  26. {
  27. struct list *l = NULL;
  28. int i;
  29.  
  30. for (i = 0; i < 42; ++i)
  31. l = ((l == NULL) ? append(&l, i) : l);
  32. print(l);
  33. }
  34.  
Success #stdin #stdout 0.01s 1852KB
stdin
Standard input is empty
stdout
0