Malloc
Malloc is needed in C because sometimes you want memory to be persistent for the life of a program, even when leaving and entering functions and so on. Malloc sets memory aside from the heap and allows it to be persistent until either freed or the program exits. Linked lists need this because we want the information in a list to exist while the main program exists. Arrays allocate space for themselves when they are made, but since they could be local variables then they are more at risk of being lost than if memory is explicitly allocated.Set the pointer to NULL after free
After freeing anything with free(), set its pointer to NULL.
This may solve some difficult-to-find bugs */
Programming Notes
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
- 【姓名】黄华珠 【派别】玉印派 【导师】袁文魁 王玉印 【分舵】集思广益队 【舵主】余祖江 【导图解说】 中心图是...
- 唯品会 用户运营专员 Buluu TIME:9.19-9.20 流程:群面-初试-复试(止步于此)-HR面 群面:...