c 動態記憶體
動態記憶體
動態記憶體可以讓使用者在定義變數時不需事先之到變數大小,使用動態記憶體需使用指標的方式儲存記憶體位置,並且在變數使用完閉後釋放記憶體空間。
Example
以struct
型式使用動態記憶體
typedef
struct{
char
*name;
int
age;
}person;
int
main(){
person
* myperson = malloc(sizeof(perosn));
myperson->name=”John”;
myperson->age
= 27;
free(myperson);
}
留言
張貼留言