Monday, 26 August 2013

Return local character array from a function [duplicate]

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
&#65533;@$&#65533;@<&#65533;&#65533;&#580;&#1541;&#65533;;&#65533;&#65533;&#65533;Y@&#65533;&#65533;&#65533;
-> string

No comments:

Post a Comment