Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
skoczymroczny
on Nov 8, 2016
|
parent
|
context
|
favorite
| on:
C for Python programmers (2011)
"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])
cluoma
on Nov 8, 2016
|
next
[–]
This only works for arrays allocated on the stack, not for heap-allocated arrays via malloc or similar.
uryga
on Nov 8, 2016
|
prev
|
next
[–]
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
kbart
on Nov 8, 2016
|
prev
[–]
It works, but keep in mind that arrays != pointers.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search:
Well, there is sizeof(array)/sizeof(array[0])