#include <stdio.h>
void printa(char *a[])
{
for (int i = 0; i < 3; ++i) {
printf("%s\n", *a);
a++;
}
}
int main(void)
{
char *a[] = {"The first", "The second", "The third"};
for (int i = 0; i < 3; ++i) {
printf("%s\n", *a);
a++; // error: cannot increment value of type 'char *[3]'
}
printa(a); //OK
return 0;
}
Thus, my question is why the code a++
in main function causing compile error (error: cannot increment value of type 'char *[3]'). But if I pass array of pointer a to function printa
and call a++
on that pointer, it works perfectly.
Thanks,