When defining a function like this:
void myFunction(arguments){
// some instructions
}
what is the deference between using char[] name
and char name[]
as the function's argument. And why not use a pointer to char instead.
When defining a function like this:
void myFunction(arguments){
// some instructions
}
what is the deference between using char[] name
and char name[]
as the function's argument. And why not use a pointer to char instead.
In other languages such as Java and C#, the location of the
[]
brackets is just syntactic sugar and doesn't affect the program in any way.C, being an older language, doesn't have that flexibility. An array must be declared with the brackets after the name.
As for when and why you would use a pointer instead, have a read here.
You will get compile error.
It is impossible to compile a code like this:
The 1st one (
char[] name
) won't compile as it's the wrong syntax.Array subcripts in definitions for the parameters of a function's implementation go to the name of (mandatory) parameter.
The correct syntax is the 2nd:
Example:
However
char[] name
will be considered invalid syntax.