In which manner array of characters is allocated memory locally?
This is the code I've written,
char *foo();
void main()
{
char *str=foo();
strcpy(str,"Holy sweet moses! I blew my stack!!");
printf("%s",str);
}
char * foo()
{
char str[256];
return str;
}
When I use char array in function foo(), the strcpy in main() function
doesn't copy the string into str. But, when I use int array in function
foo(), main() strcpy copies successfully.
i.e.
int str[256]; //in funtion foo
output
Holy sweet moses! I blew my stack!!
if
char str[256]; //in foo()
output : nothing!
No comments:
Post a Comment