後、私は次のコードでこのエラーを持っているエラー:"解放されたポインタは割り当てられませんでした。" malloc、reallocの
int main(){
point *points = malloc(sizeof(point));
if (points == NULL){
printf("Memory allocation failed.\n");
return 1;
}
other_stuff(points);
free(points);
return 0;
}
void other_stuff(point points[]){
//stuff
realloc(points, number*sizeof(point))
}
私は検索が、何の割り当てがありませんでした明確だっただけの例を発見しました。
ここでは、points
を初期化するためにmalloc
を使用し、その後サイズをrealloc
に変更しました。だから私はfree
に来るとき、どのようにポインタが "割り当てられていない"ですか?
'points'は' main'で宣言されています。 'other_stuff'はどうしたらそれにアクセスできますか? – AVP
@AVPごめんなさい。編集しました。(自分のコードにありました) – OJFord