My Code is below:
#include <stdio.h>
void print_pointer(char **str);
void print_array(char *str[20]);
void print_array2(char str[20][20]);
void print_array3(char str[][20]);
int main(int argc, char *argv[])
{
char str[20][20] = {"test1", "test2", "test3"};
print_pointer(str);
print_array(str);
print_array2(str);
print_array3(str);
return 0;
}
void print_pointer(char **str)
{
int i = 0;
for(; i < 20; i++)
{
printf("%s", str[i]);
}
}
void print_array(char *str[20])
{
int i = 0;
for(; i < 20; i++)
{
printf("%s", str[i]);
}
}
void print_array2(char str[20][20])
{
int i = 0;
for(; i < 20; i++)
{
printf("%s", str[i]);
}
}
void print_array3(char str[][20])
{
int i = 0;
for(; i < 20; i++)
{
printf("%s", str[i]);
}
}
When I compile this code, there are two compile errors encountered:
error C2664: 'print_pointer' : cannot convert parameter 1 from 'char [20][20]' to 'char ** '
error C2664: 'print_array' : cannot convert parameter 1 from 'char [20][20]' to 'char *[]'
My question is what's the actually difference between these 4 functions?
Why print_array
and print_pointer
function could not work while print_array2
and print_array3
could work properly?