Hi,

Following are two programs which behave differently for same situtaion.
Code:
 
#include<stdio.h>
char *somfun()
{
char *t="pawan";
return t;
}
int main()
{
        puts(somfun());
}
Output : pawan
Code:
 
#include<stdio.h>
char *somfun()
{
char t[]="pawan";
return t;
}
int main()
{
        puts(somfun());
}
output : garbage value

Both variable inside function "somfun" are having local scope even after that first program is printing the value of t...how is it possible???????

Last edited by shabbir; 27Sep2012 at 17:55.. Reason: Code blocks