std*_*all 0 c memory-management
在调用free()函数之后,动态分配的内存的指针指向什么.指针是否指向NULL,或者它仍指向在解除分配之前指向的相同位置.free()的实现是否具有某种标准,或者它在不同平台中的实现方式不同.
uint8_t * pointer = malloc(12);
printf("%p", pointer); // The current address the pointer points to
free (pointer);
printf("%p", pointer); // must it be NULL or the same value as before ?
Run Code Online (Sandbox Code Playgroud)
编辑:我知道printf会产生相同的结果,我只想知道我是否可以依靠不同的实现.
指针值未被修改.你通过指针(内存地址)的值来free().该free()函数无权访问pointer变量,因此无法将其设置为NULL.
这两个printf()调用应该产生相同的输出.
| 归档时间: |
|
| 查看次数: |
305 次 |
| 最近记录: |