4 ms·
You're being confused by one of the parts of C that is difficult for beginners to wrap their heads around, and is a trap from the unwary. In C, there are array
by cjensen 2y ago
You're being confused by one of the parts of C that is difficult for beginners to wrap their heads around, and is a trap from the unwary.
In C, there are arrays. If you use the identifier that names the array as a parameter to a function, it gets quietly converted to a pointer to the first item of the array and all array size information is lost.
So you can obtain the array size, but only if you are dealing with the identifier that directly names the array. If you attempt the same technique on a pointer to the array, bad things will happen.
- LiamPowell 2y ago> If you attempt the same technique on a pointer to the array, bad things will happen. Technically a pointer to the array will work as expected (i.e. void f(int (*x)[5])).