char *xyz()
{
char str[32];
strcpy(str,"Hello there!");
return(str);
}
void main()
{
printf("%s",xyz());
}
When I call xyz(), is it will return a dangling pointer ? Thanks
Yes, it is a dangling pointer. Your program invokes undefined behaviour.
On some systems it might crash your application, on others it might appear to work correctly. But either way, you should not do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With