way to get size of an array using something like sizeof?
say ive got an array eg
int abc[10];
is there someway i can use a function on it, to determine the size of the array.
eg getsize(abc) would equal 10
thanks,
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]
[edited by - jack_1313 on January 16, 2004 3:14:01 AM]
Which is the size of the array in bytes. If you want the number of elements then try sizeof(abc)/sizeof(int).
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement