Comparison of array and vector in C + + arrays

Source: Internet
Author: User

The number of elements of an array must be defined when 1:array is defined, and vectors do not need to be, and can only contain integer literal constants, enumeration constants, or integer const objects initialized with constant expressions. A const variable that is not a const variable and whose value needs to be known at run time cannot be used to define the dimensions of the array.
The space defined by the 2:array is fixed and cannot be changed, and the vector is much more flexible and can be added or reduced.
3:vector has a series of functions that are very convenient to use. Unlike vectors, arrays do not provide push--back or other actions to add new elements to the array, and once the array is defined, new elements are not allowed, and if necessary, a new memory space is allocated. The element of the member array is then assigned to the new memory space.
4. Unlike vectors, an array cannot be initialized with another array, nor can an array be assigned to another array;

Comparison of array and vector in C + + 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.