Hey guys, I really need ur help on this one!
How do I find out the length of an array using C?
for instance...
I have an array that has 10 values in it, how do I get this number programatically...
thanx in advance,
Squirrelly1;)
Printable View
Hey guys, I really need ur help on this one!
How do I find out the length of an array using C?
for instance...
I have an array that has 10 values in it, how do I get this number programatically...
thanx in advance,
Squirrelly1;)
You can't, really.
Unless you specifically have a 10 item array:...in which case you can use (sizeof(blah) / sizeof(int)) to get the number of items. If you've used malloc to obtain a pointer to a memory location, then there's no way, and you need to keep track of the size yourself.Code:void somecode() {
int blah[10];
}
And if you have int blah[10] then there's no reason to compute the size. Note also that this only works in the function you declared the array.