C語言程序設計 學習筆記 動態內存分配(malloc)

如果輸入程序時,先告訴你個數,然後再輸入,要記錄每個數據(類似動態數組) C99之前應該怎麼做呢? malloc()函數的作用就在此: int *a = (int*)malloc(n*sizeof(int)); malloc()函數的作用是向內存申請一個n*sizeof(elementtype)的內存,並返回地址,申請過來的這個大小的內存,可以直接理解爲新建了一個a[n]的數組 使用malloc(
相關文章
相關標籤/搜索