Standard library functions begin and end------C++primer

Source: Internet
Author: User

Although the trailing pointers can be computed, this usage is extremely error-prone. To make the use of pointers easier and more secure, the new C + + standard introduces two functions called Begin and end. These two functions are similar to the two members of the same name in the container, although the array is not a class type after all, so these two functions are not member functions. The correct form of use is to have arrays as their parameters:

int a[] = {0,1,2,3,4,5,6,7,8,9};int *beg = Begin (a);//Pointer to a first element int *last = end (a);//Pointer to the next position of a tail element

Cannot use dynamic array

These two functions are defined in the iterator header file.

Using these two functions makes it easy to write a loop and manipulate the elements in the array. For example:

int *pbeg=begin (a), *pend=end (a), while (pbeg!=pend&&*pbeg>=0)    ++pbeg;

Note, in particular, that the trailing pointer cannot perform dereference and increment operations.

Standard library functions begin and end------C++primer

Related Article

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.