Return local character array from a function [duplicate]
This question already has an answer here:
Can a local variable's memory be accessed outside its scope? [duplicate]
17 answers
How to return a local character array from one function
char* testfunction()
{
char array[] = "Hello World";
return array;
}
char main()
{
char* array = testfunction();
printf(" %s -> string", array);
return 0;
}
THis code results unknown error
�@$�@<��Ʉ؅�;���Y@���
-> string
No comments:
Post a Comment