you can use a static array in your method, to avoid lose of your array when your function ends :
char * createStr()
{
char char1= 'm';
char char2= 'y';
static char str[3];
str[0] = char1;
str[1] = char2;
str[2] = '\0';
return str;
}
Edit : As Toby Speight mentioned this approach is not thread safe, and also recalling the function leads to data overwrite that is unwanted in some applications. So you have to save the data in a buffer as soon as you return back from the function. (However because it is not thread safe method, concurrent calls could still make problem in some cases, and to prevent this you have to use lock. capture it when entering the function and release it after copy is done, i prefer not to use this approach because its messy and error prone.)