It depends on your requirements. The reason is that the type of str is actually str60, so when str[1][2] is used, the compiler will know that the accessed address is the byte pointed to by str+60*1+2 data (char type). This is not the same type as char**, and char ** does not contain information 60.
So to change it to legal C code, you need to change the type of the return value or force type conversion.
Remember to let the caller know the length of the array when returning char**, because the length information of the array is lost when char[] degenerates into char*. It is recommended to add an int* table length to the parameter.
You are asking how to write the return value type:
or:
It depends on your requirements.
The reason is that the type of
str
is actuallystr60
, so whenstr[1][2]
is used, the compiler will know that the accessed address is the byte pointed to bystr+60*1+2
data (char type). This is not the same type aschar**
, andchar **
does not contain information 60.So to change it to legal C code, you need to change the type of the return value or force type conversion.
Remember to let the caller know the length of the array when returning char**, because the length information of the array is lost when char[] degenerates into char*. It is recommended to add an int* table length to the parameter.
It is better to follow the method above:
The example is very rough. In fact, it must return the object created on the heap, not the stack.