Please see the following code snippet:
void foo(char str[][MAX_SIZE])
{
strcpy(str[0], "Hi");
strcpy(str[1], "Hey");
}
int main(void) {
int V = 2;
char str[V][MAX_SIZE];
foo(str);
int i;
for(i = 0; i < V; ++i)
printf("%s\n", str[i]);
return 0;
}
The output is as expected:
Hi
Hey
When the definition of foo is changed to:
void foo(char *str[MAX_SIZE]) { ... } <------------- Runtime error
It flashes Runtime error
However, wrapping the pointer in brackets works fine:
void foo(char (*str)[MAX_SIZE]) { ... } <-------------- Works fine
I guess I am getting confused between the different ways to pass a 2D array to a method.
Can you please help me understand what each definition of foo() means, what does it expect and how does it deal with the param it accepts?