This question has already been answered:
- Return the C 2 response array from the function
Is it possible in C to make the return type int* func(void) or is it more correct to return an array through a reference in the arguments of the void func(int *mass) function?
int* f() { int a[2] = {4, 5}; int* p = a; p = (int*)malloc(2 * sizeof(int)); p[0] = a[0]; p[1] = a[1]; return p; } void f(int* p) { int a[2] = {4, 5}; p[0] = a[0]; p[1] = a[1]; //use function malloc in main }