The code is as follow :
#include
int num = 3; // Static external variable
int *ptr = #
int main(void)
{
int num2 = 4; // Autom
Calling free()
on a pointer not returned by memory allocating functions(malloc
,calloc
etc) causes Undefined Behavior.
Your code has an Undefined Behavior, So the compiler does not need to give you any diagnostic of it and it can show any behavior, it might work, or crash, or literally do anything.
Just avoid writing code which causes an Undefined Behavior is the only solution.