Why freed struct in C still has data?
Posted
by kliketa
on Stack Overflow
See other posts from Stack Overflow
or by kliketa
Published on 2010-06-02T17:36:29Z
Indexed on
2010/06/02
17:44 UTC
Read the original article
Hit count: 241
When I run this code:
#include <stdio.h>
typedef struct _Food
{
char name [128];
} Food;
int
main (int argc, char **argv)
{
Food *food;
food = (Food*) malloc (sizeof (Food));
snprintf (food->name, 128, "%s", "Corn");
free (food);
printf ("%d\n", sizeof *food);
printf ("%s\n", food->name);
}
I still get
128
Corn
although I have freed food. Why is this? Is memory really freed?
© Stack Overflow or respective owner