Hi..
I can't seem to understand the difference between the different declarations on an array or a 2d array.
for instance:
void swap(char **a, char **b) {
char *t = *a;
*a = *b;
*b = t;
}
int main(int argc, char **argv) {
char a[] = "asher";
char b[] = "saban";
swap(&a,&b);
}
this code doesn't compile, it outputs:
warning: passing argument 1 of ‘swap’ from incompatible pointer type
test.c:10: note: expected ‘char **’ but argument is of type ‘char (*)[6]’
isn't a
a pointer to first cell of char array and &a
is a pointer to pointer?
another example is:
char (*c)[3];
char (*d)[3];
swap(c,d);
doesn't compile either.. is char (*c)[3]
same as a pointer to char a[] = "ab"
?
However this does compile:
char *c[3];
char *d[3];
swap(c,d);
so i'm totally confused. Why is there a difference? Is there some rules about that issue to prevent me from mistaking all the time?
Thank you all