fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct {
  5. int x, y;
  6. } Point;
  7.  
  8. void resize(Point** xyp) {
  9. int n;
  10. *xyp=(Point*)realloc(*xyp, 4*sizeof(Point));
  11.  
  12. for (n=0;n<4;n++)
  13. {
  14. (*xyp)[n].x=n;
  15. (*xyp)[n].y=n;
  16. }
  17. }
  18.  
  19. int main () {
  20. int n;
  21. Point *xy;
  22. xy=(Point*)malloc(2*sizeof(Point));
  23.  
  24. for (n=0;n<2;n++)
  25. {
  26. xy[n].x=n;
  27. xy[n].y=n;
  28. }
  29.  
  30. resize(&xy) ;
  31.  
  32. for (n = 0; n<4; n++) {
  33. printf("xy[%i].x= %i \n",n,xy[n].x);
  34. printf("xy[%i].y= %i \n",n,xy[n].y);
  35. }
  36.  
  37. free(xy);
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 2244KB
stdin
Standard input is empty
stdout
xy[0].x= 0 
xy[0].y= 0 
xy[1].x= 1 
xy[1].y= 1 
xy[2].x= 2 
xy[2].y= 2 
xy[3].x= 3 
xy[3].y= 3