Can you explain this:
void foo(const char data[10])
{
char copy[10];
const char copy1[10] = {};
printf("%i", sizeof(copy)); //prints 10, as expected
printf("%i", sizeof(copy1)); //prints 10, as expected
printf("%i", sizeof(data)); //prints 4, WTF?
}
Looks like function parameters are treated as simple pointers for sizeof.
But WHY does this happen? Is it documented anywhere?
I never saw that syntax before in C++ but maybe you meant
Anyway, in C++ arrays decay to pointers when passed to a function. So the function has no way of knowing how big the passed arrays are. In that sense, what I wrote above is completely equivalent to:
There is also a C FAQ about this subject.