[Cpp]
# Include <stdio. h>
# Include <stdlib. h>
Void main (){
Float * p = (float *) malloc (sizeof (float ));
// Apply for a space. If the request succeeds, return the space address. If the request fails, return NULL.
* P = 10.0; // value assignment
Printf ("memory value = % f \ n", * p );
Printf ("memory address = % p \ n", p );
Free (p); // release space
Printf ("value in memory after release = % d \ n", * p );
Printf ("memory address after release = % p \ n", p );
// After the space is released, the memory space does not disappear and the address of the space still exists;
// The system is handed over to other programs for use. If you use this space address again,
// It will destroy the data in it
// The second release is required at this time:
// Free (p );
// But this will cause errors. To avoid errors, remember to perform the following operations:
P = NULL;
Printf ("memory address after clearing = % p \ n", p );
}
Result:
Memory value = 10.000000
Memory Address = 00540F08
Value in memory after release =-1610612736
Memory Address after release = 00540F08
Memory Address after clearing = 00000000
Press any key to continue
From like7xiaoben