You can't declare a function returning an array.
ISO/IEC 9899:1999
§6.9.1 Function definitions
¶3 The return type of a function shall be void
or an object type other than array type.
C2011 will say essentially the same thing.
You shouldn't ever return a pointer to a (non-static) local variable from a function as it is no longer in scope (and therefore invalid) as soon as the return completes.
You can return a pointer to the start of an array if the array is statically allocated, or if it is dynamically allocated via malloc()
et al.
int *function1(void)
{
static int a[2] = { -1, +1 };
return a;
}
static int b[2] = { -1, +1 };
int *function2(void)
{
return b;
}
/* The caller must free the pointer returned by function3() */
int *function3(void)
{
int *c = malloc(2 * sizeof(*c));
c[0] = -1;
c[1] = +1;
return c;
}
Or, if you are feeling adventurous, you can return a pointer to an array:
/* The caller must free the pointer returned by function4() */
int (*function4(void))[2]
{
int (*d)[2] = malloc(sizeof(*d));
(*d)[0] = -1;
(*d)[1] = +1;
return d;
}
Be careful with that function declaration! It doesn't take much change to change its meaning entirely:
int (*function4(void))[2]; // Function returning pointer to array of two int
int (*function5[2])(void); // Array of two pointers to functions returning int
int (*function6(void)[2]); // Illegal: function returning array of two pointers to int
int *function7(void)[2]; // Illegal: function returning array of two pointers to int