C functions cannot return array types. The types of returned functions can be any, except for "array T" or "function returning T". Also note that you cannot assign array types; that is, code like the following will not work:
int a[10]; a = foo();
Arrays in C are handled differently than other types; in most contexts, the type of an array expression is implicitly converted ("decomposed") from an "N-element array T" to a "pointer to T", and its value is set to point to the first element in the array. The exceptions to this rule are when the array expression is an operand of either sizeof operators or addresses ( & ), or when the expression is a string literal used to initialize another array in the declaration.
Given an announcement
T a[N];
for any type T, then the following is true:
Expression Type Decays to Notes
---------- ---- --------- -----
a T [N] T * Value is address of first element
& a T (*) [N] n / a Value is address of array (which
is the same as the address of the
first element, but the types are
different)
sizeof a size_t n / a Number of bytes (chars) in array =
N * sizeof (T)
sizeof a [i] size_t n / a Number of bytes in single element =
sizeof (T)
a [i] T n / a Value of i'th element
& a [i] T * n / a Address of i'th element
Due to the implicit conversion rule, when you pass an array argument to a function, what the function receives is the value of the pointer, not the value of the array:
int a[10]; ... foo(a); ... void foo(int *a) {
Please note that something like
int *foo(void) { int arr[N]; ... return arr; }
does not work; one of the functions comes out, the arr array technically no longer exists, and its contents can be overwritten before you can use it.
If you do not dynamically allocate buffers, it is best to pass the arrays that you want to change as arguments to the function along with their size (since the function receives only the pointer value, it cannot determine how large the array is):
int a[10]; init(a, sizeof a / sizeof a[0]);