Archived

This topic is now archived and is closed to further replies.

johnnyBravo

way to get size of an array using something like sizeof?

Recommended Posts

jack_1313    536
Why not use sizeof and then divide the result by the size of the array datatype (ie int in the example you provided)?

[edited by - jack_1313 on January 16, 2004 3:14:01 AM]

Share this post


Link to post
Share on other sites
SiCrane    11839
Which is the size of the array in bytes. If you want the number of elements then try sizeof(abc)/sizeof(int).

Share this post


Link to post
Share on other sites
Alimonster    185
Watch out though -- if you pass arrays to functions as pointers, this trick won''t work inside the functions (it''ll give you 4 bytes for the array size as it will just be a pointer). It''s best to either keep a note of the array size in a variable and pass it around or to use a genuine container class (e.g. std::vector) which will keep an internal note of the size.

Share this post


Link to post
Share on other sites