Just as with arrays and pointers, there are a number of ways to pass a string to a function:
- The first way is to pass the string explicitly, giving the array size of the string, as follows:
Func1( char[8] aStr );
This parameter declaration allows a string of up to seven characters, as well as the terminating nul character ('\0'), to be passed into Func1(). The compiler will verify that the array being passed in has exactly 8 char elements. This is useful when we are working with strings of limited size.
- The next way is to pass the string without specifying the char array size, as follows:
Func2( char[] aStr );
Func3( int size, char[] aStr );
In Func2(), only the string name is passed. Here, we are depending on the fact that there is '\0', a nul character in aStr. To be safer, the size of the string, as well as the string itself, can be passed...