say you have a(char *s){...} and b(char s[]){...}
How are strings passed in treated differently when arguments in functions are declared in this way? Or are they 100% interchangeable?
say you have a(char *s){...} and b(char s[]){...}
How are strings passed in treated differently when arguments in functions are declared in this way? Or are they 100% interchangeable?
Completely interchangeable. In this instance only (as the formal parameter of a function declaration), [] means pointer.
In your example, they're interchangeable (apart from your functions having different names, of course).
Note that this does not mean an array and a pointer are the same things - they are not, but a trap for a lot of beginners (and a few too many experts, and even a few textbooks) is believing they are the same.
When passing a single-dimensional array to a function, the compiler quietly converts the name of the array passed into a pointer (to the first element). However, that type of conversion is not universal - for example, the compiler is required to complain bitterly if two-dimensional array is passed directly to a function expecting a pointer-to-pointer (or vice versa).
in this case, they are the same, u don't know whether the arg is a array or a string