fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct Node {
  5. int value;
  6. struct Node *next;
  7. } Node;
  8.  
  9. int main(void)
  10. {
  11. Node *head = malloc(sizeof(Node));
  12. Node *second = malloc(sizeof(Node));
  13. Node *third = malloc(sizeof(Node));
  14.  
  15. head->value = 10;
  16. head->next = second;
  17.  
  18. second->value = 20;
  19. second->next = third;
  20.  
  21. third->value = 30;
  22. third->next = NULL;
  23.  
  24. // Проходим по списку
  25. Node *current = head;
  26.  
  27. while (current != NULL) {
  28. printf("%d\n", current->value);
  29. current = current->next;
  30. }
  31.  
  32. // Освобождаем память
  33. free(third);
  34. free(second);
  35. free(head);
  36.  
  37. return 0;
  38. }
  39.  
  40.  
  41.  
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
10
20
30