#include <stdio.h>
int* function1(void);
int main()
{
int x = 10;
int *p = function1();
printf("%d\n", *p);
printf("%d\n", p);
}
int* function1(void)
{
int z;
z = 20;
z++;
return &z;
}
- Variable 'z' is local to the 'function1', and is not alive after the 'function1' is terminated.
- Now to access the value at the memory space of the variable 'z', its address is returned by the function.
- So, even after the termination, will the memory space of the variable 'z' will still be reserved, as the pointer accesses the variable?, in such case what will be the properties of the memory space?
- Or What if some-other variable is allocated with the same memory space of variable 'z'?
Note: GCC compiler of code blocks has compiled the program successfully, without any error and warning.