Comparison of array and vector in C ++

Source: Internet
Author: User
1: When an array is defined, the number of elements in the array must be defined, while that of the vector is not required. It can only contain constants of the nominal value of an integer, enumerated constants, or integer const objects initialized using a constant expression, non-const variables and the const variables whose values need to be known in the running stage cannot be used to define the dimension of the array. 2: The space defined by array is fixed and cannot be changed. The vector is much more flexible and can be added or subtracted. 3: vector has a series of function operations, which are very convenient to use. unlike vector, the array does not provide push-back or other operations to add new elements to the array. New elements cannot be added once defined. If necessary, a new memory space must be allocated, then, assign the element of the member array to the new memory space.

4. arrays are different from vectors. An array cannot be initialized with another array or assigned to another array;

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.