Originally Posted by
robwhit
You can use pointer arithmetic with the pointer version, not with the others.
The 2nd one has an unspecified number of elements, the first one has a specifed number of elements. That means that if you enter in an invalid index constant in the first one, you'll probably get a compile error.
And whatever other differences are in the link.
They're all the same; note that these are prototypes, and as a parameter of a prototype, what looks like an array is really a pointer (this is not the case elsewhere, of course).
You can indeed do pointer arithmetic with the parameter of all three methods because they are identical. You can do pointer arithmetic on arrays, too (because arrays decay into pointers in most cases), but I presume you mean something like employee++? That's still possible with all the prototypes I showed due, again, to the fact that arrays aren't really arrays (in this particular context).
Here's a demonstration:
Code:
#include <stdio.h>
static void f1(int *p)
{
printf("%d\n", *++p);
}
static void f2(int p[])
{
printf("%d\n", *++p);
}
int main(void)
{
int a[] = { 1, 2 };
f1(a);
f2(a);
return 0;
}
I used a single array for simplicity; this naturally holds for multidimensional arrays, but it gets slightly more complicated because you start to deal with pointers to arrays.
You can, perhaps, further convince yourself with this:
Code:
#include <stdio.h>
static void f(char p[11])
{
printf("In f(): %lu\n", (unsigned long)sizeof p);
}
int main(void)
{
char a[11];
printf("In main(): %lu\n", (unsigned long)sizeof a);
f(a);
return 0;
}
Unless you're on an absolutely bizarre system, two different numbers should come out: 11 in main() (this won't change regardless of platform), and probably 4 in f() (depending on the size of a pointer).
Despite the fact that it looks like an array, inside the function f(), p is a pointer.
This is covered in section 6.4 of the FAQ link you posted.