fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.  
  5.  
  6. typedef struct node * list;
  7. struct node {
  8. int key;
  9. list next;
  10. };
  11.  
  12. list L = NULL;
  13. L = malloc(sizeof(*L));
  14. L->key = 5; // аналог L^.key ; Можно: (*L).key
  15. L->next = malloc(sizeof(*L));
  16. L->next->key = 10;
  17. L->next->next = malloc(sizeof(*L));
  18. L->next->next->key = 12;
  19. L->next->next->next = NULL;
  20.  
  21. list p = L, q;
  22.  
  23. while (p!=NULL) {
  24. printf("%d ",p->key); // будет выдано 5 10 12
  25. p = p->next;
  26. }
  27. printf("\n");
  28. p = L;
  29. while (p!=NULL) {
  30. q = p;
  31. p = p->next;
  32. free(q);
  33. }
  34.  
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 4316KB
stdin
0 Hello World.
stdout
5 10 12