Home > Back-end >  Why, what did free
Why, what did free

Time:10-30

 # include & lt; stdio.h> 
#include
Int main ()
{
Int * p;
//p=(int *) malloc (sizeof (int));
* p=5;
Printf (" % p % d \ n, p, * p).

//free (p);
//* p=6;

//printf (" % p % d \ n, p, * p).

return 0;
}

P no initialization, there is no any output
While the program execution to get reasonable results
 # include & lt; stdio.h> 
#include
Int main ()
{
Int * p;
P=(int *) malloc (sizeof (int));
* p=5;
Printf (" % p % d \ n, p, * p).

Free (p);
//* p=6;

Printf (" % p % d \ n, p, * p).

return 0;
}

0 x55e7822282a0 5
0 x55e7822282a0 0

But why did the following procedure to release the application memory * P will be assignment 6?
 # include & lt; stdio.h> 
#include
Int main ()
{
Int * p;
P=(int *) malloc (sizeof (int));
* p=5;
Printf (" % p % d \ n, p, * p).

Free (p);
* p=6;

Printf (" % p % d \ n, p, * p).

return 0;
}

0 x55e5857e22a0 5
0 x55e5857e22a0 6
  • Related