When the variable is defined inside some block it gets destroyed when the end of the block is reached.
So from the below program I expected some kind of warning
#include<stdio.h>
int *fun()
{
int i=10;
return &i;
}
int main(void)
{
int *p=fun();
return 0;
}
I expect a warning as I am trying to return the address of the local variable i which will be destroyed when the control comes out of the scope
But if I store the value variable i in some integer pointer and then return the value from the fun like this
#include<stdio.h>
int *fun()
{
int i=10,*p;
p=&i;
return p;
}
int main(void)
{
int *p=fun();
return 0;
}
Why I dont get any warning ?