The code is as follows:
#include <stdlib.h> int num = 3; // Static external variable int *ptr = # int main(void) { int num2 = 4; // Automatic variable int *ptr2 = &num2; free(ptr); //Free static variable free(ptr2); //Free automatic variable return 0; }
I am trying to compile the above code and it works, I am curious if a function can free()release both a static variable and an automatic variable? Or basically does nothing?
free()
free() , (malloc, calloc ..) Undefined .Undefined Behavior, - , , - .
malloc
calloc
, Undefined - .
. free , malloc .
free
num . num2 main , main .
num
num2
main
, free. , malloc/free . free , - , . , malloc, - . , - .