Y
Hacker News
new
|
ask
|
show
|
jobs
by
skoczymroczny
3517 days ago
"C does not have an support for accessing the length of an array once it is created"
Well, there is sizeof(array)/sizeof(array[0])
3 comments
cluoma
3517 days ago
This only works for arrays allocated on the stack, not for heap-allocated arrays via malloc or similar.
link
uryga
3517 days ago
I remember trying that, and I think it only works in the scope where you declared the array. So for example if you pass the array to a function, the size info is lost. Might be because of the "arrays decay to pointers" thing
link
kbart
3517 days ago
It works, but keep in mind that arrays != pointers.
link