I wrote a program in C having dangling pointer.
#include int *func(void) { int num; num = 100; return # } int func1(void
Returning a pointer to a local variable yields undefined behaviour, which means that anything the program does (anything at all) is valid. If you are getting the expected result, that's just dumb luck.