Here’s a sample program:
#include <stdio.h>
void foo(int b[]){
printf("sizeof in foo: %i\n", sizeof b);
}
int main(){
int a[4];
printf("sizeof in main: %i\n", sizeof a);
foo(a);
}
The output is:
sizeof in main: 16
sizeof in foo: 8
Question is, what’s the point of that syntax if it’s just converted to a standard pointer at the function boundary?
It’s syntactic sugar:
void foo(int b[])suggests thatbis going to be used as an array (rather than a single out-parameter), even though it really is a pointer.It’s a left-over from early versions of C, where postfix
[]was the syntax for a pointer declaration.