Hello all,
I stuck to a problem
Statement: i define two function one returning a string and other a single char.
the code is work fine it successfully return string "martin" and a char 'a'....
but if i remove the word static from func(),like,Code:char *func(void) { static char Text2[10]="martin"; return (Text2); } char* funchar(void) { char ch; ch = 'a'; return &ch; } main() { char *Text1; char *Text2; char* c; Text1 = func(); printf("\ntext1:%s",Text1); Text2 = "outside"; printf("\ntext2:%s",Text2); c = funchar(); printf("\nc:%c",*c); getch(); }
than this function return a garbage but as in funchar() i didn't declare char ch as static still it return 'a'.Code:char *func(void) { char Text2[10]="martin"; return (Text2); }
Why this is happen..?
Do array whether it is a char array or and other(int ,double) , only its location is stored in stack means actually the string "martin" stored somewhere else but its reference will stored in stack.
Or the whole string "martin" will stored in stack.?
Thanks,
Gunjan



LinkBack URL
About LinkBacks


