Trying to write a function which will return a string.
char *type(int type) {
switch (type) {
case 1: return "type 1";
case 2: return "type 2";
default: return "type 3";
}
}
Is this the right way to return string? There is no space been allocated for the string by malloc or calloc. So, what's the lifecycle of them? Will the caller allocate new space to store the returned string?