Why freed struct in C still has data?

后端 未结 7 1196
梦毁少年i
梦毁少年i 2020-12-02 02:42

When I run this code:

#include 

typedef struct _Food
{
    char          name [128];
} Food;

int
main (int argc, char **argv)
{
    Food  *f         


        
7条回答
  •  一个人的身影
    2020-12-02 03:07

    There is nothing like free food :) When you "free" something, it means that the same space is again ready to be used by something else. It does NOT mean filling it up by garbage. Secondly, the pointer value has not changed -- if you are seriously coding you should set a pointer to NULL once you have freed it so that potential junk accesses like this do not happen.

提交回复
热议问题