Results 1 to 2 of 2

Thread: is the size of the array changeable

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    108

    is the size of the array changeable

    can we change the size of the array? in other words, if we intialize the array size to a size, say 10 elements, later in the process we might have to store something more than 10 elements. Can the size of the array automatically expand?

    Thanks.

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: is the size of the array changeable

    Not a standard array. In this case, you must create an array of a larger size, copy the elements over, and deallocate the old array (c++). In C using malloc/free, you can call realloc() to resize dynamically allocated memory.

    In C++, it is better to use some sort of STL container, such as a vector. vectors will grow in size automatically.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width