本人解答供參考
#include?<stdio.h> #include?<stdlib.h> struct?Score{ ????int?math; }?typedef?score; Score?*?getScore(){ ????score?*?arr?=?(Score?*)malloc(20?*?sizeof(Score)); ????for(int?i=0;i<20;i++){ ????????arr[i].math?=?i; ????} ????return?arr; } int?main(){ ????score?*?arr?=?getScore(); ????for(int?i=0;i<20;i++){ ????????printf("%d\n",arr[i].math); ????} ????return?0; }
2022-06-29
malloc的空間后面需要free掉