I'm using VScode to practice C and i'm trying to find what exactly does the free() function do to the pointer and the value inside that pointer. Here is my test code
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
int main(void)
{
int *n = malloc(sizeof(int));
*n = 1;
printf("%p %i\n",n, *n);
free (n);
printf("%p %i\n",n, *n);
return 0;
}
when i run the code, here is what i get
0x56405d2e72a0 1
0x56405d2e72a0 1678103271
what i wanted to know is why is the pointer still the same but the value inside have been changed to some kind of garbage value and what does free() explicitly do to the memory ?