Although arrays and pointers may seem interchangeable, they differ in one important aspect; the array has a size. However, due to the fact that the array passed to the function "decomposes" into a pointer, size information is lost.
The fact is that at some point you know the size of the object - because you selected it or declared it a specific size. C undertakes to maintain and disseminate this information as necessary. So after your example:
char s[80] = "";
There is no βmagicβ method for determining the size of an array within someFunction() , since this information is discarded (for performance and efficiency reasons) C is relatively low in this regard and does not add code or data that is not explicit); if information is needed, you must explicitly pass it on.
One of the ways that you can pass a string and save size information, and even pass a string by copying, rather than a link, is to wrap the string in the structure like this:
typedef struct { char s[80] ; } charArray_t ;
then
charArray_t s ; int i = someFunction( &s ) ;
with the definition of someFunction() as:
int someFunction( charArray_t* s ) { return sizeof( s->s ) ; }
However, you do not earn much, just avoid the extra option; in fact, you are losing some flexibility because someFunction() now only accepts the fixed length of the array defined by charrArray_t , and not any array. Sometimes such restrictions are useful. A feature of this approach is that you can pass by copy :
int i = someFunction( s ) ;
then
int someFunction( charArray_t s ) { return sizeof( ss ) ; }
since structures, unlike arrays, can be transferred this way. You can also return a copy. However, this may be somewhat ineffective. Sometimes convenience and safety outweigh inefficiency.