fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4.  
  5. typedef struct elemento *ponteiro;
  6.  
  7. struct elemento {
  8. int chave;
  9. ponteiro prox;
  10. };
  11.  
  12.  
  13.  
  14. main() {
  15. ponteiro p,prim,h,q;
  16. int i;
  17.  
  18. prim=NULL;
  19. p=(ponteiro)malloc(sizeof(struct elemento));
  20. h=p;
  21. p->chave=1; //ERRO
  22. (*p).chave = 1;
  23.  
  24. for(i=0; i<3; i++) {
  25. q=(ponteiro)malloc(sizeof(struct elemento));
  26. q->chave=p->chave+2;
  27. printf("%d %d %d",h->chave, p->chave, q->chave);
  28. p=q;
  29. }
  30.  
  31. printf("%d %d %d",h->chave,p->chave,q->chave);
  32. }
  33.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
1 1 31 3 51 5 71 7 7