Alternatives to arrays

Source: Internet
Author: User

Vector: Included in namespace Std

Vector<typename> name (N_elem);//Create a vector object named name, which can store n_elem elements of type TypeName

function is more powerful than arrays, but inefficient

Array

Array<typename, n_elem> name;//creates an array object named name that stores N_elem elements of type TypeName.

N_elem can not be variable, efficient and array-like, but more secure and convenient.

Array, Comparison of Array,vector

Each element can be accessed using standard array notation

Array objects can be assigned to another array object, and arrays must be assigned value by element;

Array objects and arrays are stored in the same memory area (stack), and vector objects are stored in free storage or heap;

Arrays tend to be hyper-bounded, unsafe to behave, array and vector objects can also be accessed out of bounds, but can be prevented by member functions at ();

When you use at (), illegal indexes are captured during run time, and the program is interrupted by default, and this extra check causes the runtime to grow longer.

There are also member functions, begin (), and end () to determine the bounds.

Alternatives to arrays

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.