In the next code segment, after free(x), why ybecomes 0?
According to my understanding, the memory in the heap that it pointed to x, and still pointed to y, was not assigned to someone else, as it could change to 0
And more than that, I don’t think it is free(x)that which changed it to 0.
Any comments?
#include <stdio.h>
int main(int argc, char *argv[])
{
int *y = NULL;
int *x = NULL;
x = malloc(4);
*x = 5;
y = x;
printf("[%d]\n", *y);
free(x);
printf("[%d]\n", *y);
return 0;
}
source
share