Then what is return type char* for if I can not rely on it?
Imagine cutting a bunch of arrows out of foam board. On each one, write the name of a part of your body. Tape them to the wall of your office/classroom/whatever, pointing to the relevant parts of your body when you are standing against the wall.
If someone comes in and follows the pointer to left elbow, they can find your left elbow, right?
Those arrows are equivalent to the pointers in your code.
Now, you go home at the end of your class/workday. That is the equivalent of the function ending.
Do those arrows taped on the wall still point to parts of your body? Of course not.
Now suppose one of those arrows said desk on it, and pointed at the desk. You leave to go home, and that pointer still points to your desk, right? So, that pointer is sill valid. You can rely on it.
Pointers need to point to things that are NOT going to go away at the end of a function.
What you need to do is look at reference variables, rather than pointers. In the caller, define an array, and pass a reference to that array to the function. The function can then modify the contents, but not the address of, that array. The function then doesn't need to return anything.