-
October 3rd, 2009, 05:33 PM
#1
How can one determine length of an array
Suppose if an integer array along with some integer number is passed to a function. Then how can we check whether the length of array and the value of the integer number passed are equal or not.
-
October 3rd, 2009, 06:04 PM
#2
Re: How can one determine length of an array
Don't use C-style arrays. Use C++ vectors and pass by reference.
-
October 3rd, 2009, 06:08 PM
#3
Re: How can one determine length of an array
C does not support this feature for bare arrays in general.
In the specific case of fixed-size arrays on the stack, it may be possible using templates, but that's really more of a curiosity than anything that would actually be done.
In general you should use a class which wraps the array and stores its size, such as std::vector, or else keep a separate variable around which denotes the array size.
-
October 4th, 2009, 01:45 AM
#4
Re: How can one determine length of an array
Originally Posted by shivamskn
Suppose if an integer array along with some integer number is passed to a function. Then how can we check whether the length of array and the value of the integer number passed are equal or not.
A static array will become part of the upcoming C++ standard. It's already available in namespace std::tr1 in many compilers and it's also in Boost,
http://www.codeguru.com/cpp/cpp/cpp_...le.php/c15257/
-
October 4th, 2009, 07:12 AM
#5
Re: How can one determine length of an array
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|