fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct node {
  4. int x;
  5. struct node* next;
  6. } *Node;
  7.  
  8. void advance_node(Node ptr) {
  9. ptr = ptr->next;
  10. while (ptr) {
  11. printf("%d\n", ptr->x);
  12. ptr = ptr->next;
  13. }
  14. }
  15.  
  16. int main() {
  17. Node node1 = malloc(sizeof (*node1));
  18. Node node2 = malloc(sizeof (*node2));
  19. Node node3 = malloc(sizeof (*node3));
  20.  
  21. node1->x = 1;
  22. node1->next = node2;
  23.  
  24. node2->x = 4;
  25. node2->next = node3;
  26.  
  27. node3->x = 9;
  28. node3->next = NULL;
  29.  
  30. advance_node(node1);
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
4
9