News for hackers. Stuff that matters.
Re:Learn C Programming with Open-Source Books by DSMan195276 on Monday February 06, 2017 @01:32PM (#13582440)
I think it's worth clarifying that arrays declared in parameter lists are simply just pointers. It's 100% syntactic sugar. So the `int a[n]` is simply treated as `int * a`, and the value inside of the `[]` is ignored completely. This leads to the weird situation that you declared it as `int a[n]`, but `sizeof(a)` just gives the size of a pointer, not the size of the array.

The only special case is `int a[static n]`, which does tell the compiler that `a` has at-least `n` entries. But `a` is still just a pointer in this instance, so `sizeof(a)` still gives the size of a pointer.

Personally, I'd recommend avoiding the syntax purely because of the `sizeof` issue, but its up to you.

There are no comments on this comment yet.