fork download
  1. #include <stdio.h>
  2.  
  3. struct node {
  4. int value;
  5. struct node * next;
  6. };
  7.  
  8. int main(void)
  9. {
  10. int i=0;
  11. struct node top;
  12. struct node *newNode,*tmp;
  13. top.next=NULL; //うまくバグになる良いのだが */
  14. top.value=0;
  15. for (i=0;i<10;i++) {
  16. newNode=(struct node *) malloc(sizeof(struct node));
  17. newNode->next=top.next;
  18. newNode->value=i*3;
  19. top.next=newNode;
  20. }
  21. tmp=&top;
  22. while(tmp!=NULL) {
  23. printf("%d\n",tmp->value);
  24. tmp=tmp->next;
  25. }
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0.02s 1808KB
stdin
Standard input is empty
stdout
0
27
24
21
18
15
12
9
6
3
0