When you pass an array to a function in C, the function does not receive a copy. The array name decays to a pointer to its first element, so the function gets an address and works on the caller's data. Because the size is lost in that conversion, you pass the length as a separate argument, usually of type size_t.
This is the rule behind how to pass an array to a function in C, and it explains most array bugs in function code.
In most expressions, an array name becomes a pointer to element 0. A call like sum(values, 5) passes &values[0]. These three parameter declarations are identical to the compiler.
Writing a[] is only clearer documentation. The 5 in the third form does nothing, so the function can still be called with an array of any length.
Compute n in the caller, where values is still a real array. Pass const when the function only reads, so the compiler stops accidental writes.
Inside the function the parameter is just a pointer, so sizeof a is the size of a pointer, not of the array.
The numbers assume a 4-byte int and an 8-byte pointer (a typical 64-bit system). GCC and Clang warn about this mistake with -Wsizeof-array-argument.
Because the function has the address of the original, writes are visible to the caller.
To keep the original unchanged, copy it first or return a new array. A function cannot return a local array, because that storage ends when the function returns; return a pointer to heap memory or fill a buffer supplied by the caller.
C99 added syntax that documents the minimum length, and lets the bound depend on an earlier parameter.
static n promises that a points to at least n elements, which lets the compiler optimise and warn if a caller passes a shorter array. This is a C feature, not valid in C++. Variable-length array parameters are optional in later standards, so check your compiler before depending on them in portable code.
For a 2d array the column count must be part of the type.
Strings are char arrays that end with '\0', so a function taking const char *s can find the end itself and needs no separate length.
Wrapping the array in a struct makes it pass by value, copying all elements. This is rarely worth it for large arrays but is handy for small fixed-size values such as a 3-vector.
C always passes by value, but the value passed for an array is a pointer to its first element. In effect the function works on the caller's array.
It does not. Pass the length as another parameter, or end the data with a sentinel as C strings do.
Use size_t, the type sizeof produces and the one the standard library uses.
Yes, declare the parameter const int *a. Attempts to write through it then fail to compile.
To pass an array to a function in C, pass its name, which decays to a pointer to the first element, together with its length. The function can change the caller's data unless you use const, sizeof inside the function measures the pointer, and a 2d array needs its column count in the parameter type.