- Where is the length information (invoice / size) stored when "a" is declared?
It is not stored anywhere. The sizeof operator (used in the COUNT() macro) returns the size of the entire array when it sets the true array as an operand (as in the first printf() )
- Why is length information (score / size) lost when "a" is passed to the test () function?
Unfortunately, in C, array parameters for functions are fictitious. Arrays are not passed to functions; the parameter is treated as a pointer, and the array argument passed in the function call gets "fades out" into a simple pointer. The sizeof operator returns the size of the pointer, which does not correlate with the size of the array that was used as the argument.
As a side note in C ++, you can have a function parameter as a reference to an array, in which case the full type of the array becomes available to the function (i.e. the argument does not break into a pointer and sizeof returns the size of the full array). However, in this case, the argument must exactly match the type of the array (including the number of elements), which makes the technique mostly useful only with templates.
For example, the following C ++ program will do what you expect:
#include "stdio.h"
source share