The line with the error comment is clear to me, old_buffer is treated like an address so this can't work because the array is missing information how much memory should be allocated.
That's close, but it's not exactly what's happening: the line with the error is not syntactically correct - if you change it to
char *arr2 = old_buffer;
it will work. However, this would not be an array, it would be a pointer. It would allow array-like access, but it would not give you the correct value in the sizeof
.
But why is this working in the head of a function?
Because when you pass an array to a function, the size is always ignored. It is said that the array decays to a pointer. In other words, your declaration is identical to this:
void foo(char *arr)