C pointer notation compared to array notation: When passing to function

When you declare a function parameter as an array, the compiler automatically ignores the array size (if any) and converts it to a pointer. That is, this declaration:

int foo(char p[123]);

is 100% equivalent to:

int foo(char *p);

In fact, this isn’t about notation but about the actual type:

typedef char array_t[42];
int foo(array_t p);  // still the same function

This has nothing to do with how you access p within the function. Furthermore, the [] operator is not “array notation”. [] is a pointer operator:


is 100% equivalent to:

*(a + b)

Leave a Comment