0

Return an array from a function

Good afternoon, can anyone explain how to return an array from a function using pointers?

11th Oct 2018, 12:07 AM
Š”ŠµŃ€Š³ŠµŠ¹ ŠŗуŠ·ŠøчŠµŠ²
Š”ŠµŃ€Š³ŠµŠ¹ ŠŗуŠ·ŠøчŠµŠ² - avatar
2 Answers
+ 3
array types are like int[] double[], you can return them like any good ol' datatype.
11th Oct 2018, 2:48 AM
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬ - avatar
+ 1
In C: char* strfunc (void) { char *ret = malloc(100); if ( 0 > sprintf(ret, "Hello World\n\0") ) { free(ret); ret = NULL; } return ret; } int main (int argc, char **argv) { char *arr = strfunc(); if (arr == NULL) return -1; int ii = strlen(arr) -1; printf("Array:\n"); while (ii > -1) printf("%c", arr[ii]); printf("\n"); free(arr); return 0; }
11th Oct 2018, 2:49 AM
non