Functions cannot return arrays, period. You can, of course, a pointer or take a pointer to a block of memory that has been allocated by the caller. So in your case ...
int *ret = malloc(255 * sizeof int);
However, this changes the semantics of your code. The subscriber of your function is now responsible for calling free() on the returned pointer. If they do not, you will have a memory leak, so this will add some complexity that was not there before. Instead, I would prefer something like this:
void charpos(int *p, size_t size, const char *str, char ch) {
If I did not answer your question, you need to clarify for me (us). You are not returning an array right now; you return a pointer to an int that refers to the first element of a statically allocated array.
Ed S. source share