REFERENCING DE-ALLOCATED MEMORY:
This problem occurs when the address of the local variable is returned from a function or the programmer deletes the allocated memory mistakedly.
*y=3; A SERIOUS BUG (You’ll get the full explanation in the article Memory Management)
After the execution of statement1 in the main, the memory map is as:
Now we have reached the function abc (), the execution of statement1 of function abc() results into following memory map:
But when the function abc() returns, the address of the variable x is stored in y and INTENTION is to use x as pointee of y. But with the return of the function abc(), the stack frees the variable x. Hence memory location of x can be used somewhere else by the Operating System.
The non-belonging memory is the memory which doesn’t belong to the program anymore. Hence the situation now is similar to the DANGLING POINTER case. Hence the 2nd statement of main() may cause ERROR.
Note: REFER TO THE ARTICLE MEMORY MANAGEMENT FOR BETTER UNDERSTANDNG