Why doesn't free(p) set p to NULL?

前端 未结 9 1084
一向
一向 2020-12-10 12:33

Any reasons why this can not be standard behavior of free()?

multiple pointers pointing to the same object:

#include 
#i         


        
9条回答
  •  -上瘾入骨i
    2020-12-10 12:56

    If it did, you would have to pass a pointer to a pointer to the function:

    int * p = malloc( sizeof( int ));
    free( & p );
    

    which I'm sure many people would get wrong.

提交回复
热议问题