fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct node {
  4. int value;
  5. struct node *next;
  6. };
  7. struct node *push(struct node *list, int value) {
  8. struct node *prev = malloc(sizeof *list);
  9. prev->value = value;
  10. prev->next = list;
  11. return prev;
  12. }
  13. struct node *pop(struct node *list, int *value) {
  14. struct node *next = list->next;
  15. *value = list->value;
  16. free(list);
  17. return next;
  18. }
  19. void each(void (*f)(int), struct node *p) {
  20. for (; p; p = p->next) f(p->value);
  21. }
  22. void print_int(int x) {printf("%d", x);}
  23. int main() {
  24. struct node *list;
  25. int a, b, c;
  26. each(print_int, list = push(push(push(NULL, 1), 2), 3));
  27. printf("\n%d%d%d%d", a, b, c, list = pop(pop(pop(list, &a), &b), &c));
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 4284KB
stdin
Standard input is empty
stdout
321
3210