example1
// function that return array of char in C language char * createStr() { char char1= 'm'; char char2= 'y'; char *str = malloc(3); str[0] = char1; str[1] = char2; str[2] = '\0'; return str; }Sour:ecwww.lautturi.com
example2
/* Example: return char array in C language */ #include <stdio.h> #include <stdlib.h> char *foo(int count) { char *ret = malloc(count); if(!ret) return NULL; for(int i = 0; i < count; ++i) ret[i] = i+'0'; return ret; } int main(){ int count = 5; char* chrArr = foo(count); printf("%s",chrArr); return 0; }
example of output:
01234 Process returned 0 (0x0) execution time : 0.091 s