Warning : returns address of a local variable YET correct output
This problem was suggested to me by a friend.
The code is -
Compiling this on GCC gives the above warning because k is a local variable and it will go out of scope once the function returns. Yet, when I run the program I get a perfectly correct output. That is 35. Why is this? Shouldn't I be getting garbage value?
/* Returning a pointer to an out of scope variable */
# include <stdio.h>
int k = 35;
j = fun();