How can one determine length of an array
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: How can one determine length of an array

  1. #1
    Join Date
    Sep 2009
    Location
    Pune, India
    Posts
    14

    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.

  2. #2
    Join Date
    May 2002
    Posts
    1,435

    Re: How can one determine length of an array

    Don't use C-style arrays. Use C++ vectors and pass by reference.

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    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.

  4. #4
    Join Date
    May 2009
    Posts
    2,413

    Re: How can one determine length of an array

    Quote Originally Posted by shivamskn View Post
    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/

  5. #5
    Join Date
    Sep 2009
    Location
    Pune, India
    Posts
    14

    Re: How can one determine length of an array

    k..... thank u guys

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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center