C + + new attribute string, vector and array notes

Source: Internet
Author: User


Range for (range for)

1 for (declaration:expression)

2 statement
Vectors and arrays are collections of objects, and references are not objects.

Vector objects can grow more efficiently, and it is not necessary to set their size when defining a vector object, in fact, if the performance may be worse.

C++11 new features: Cbegin () & Cend ()
To make it easier to get the return value of the Const_iterator type specifically, the c++11 new standard introduces two new functions, Cbegin () and Cend () respectively.

How do you understand complex array declarations?

1 int *ptrs[10]; Ptrs is an array that contains 10 integer pointers
2 int &refs[10] =/*?*/; Error, no referenced array
3 int (*parray) [+] = &arr; Parray points to an array containing 10 integers
4 int (&ARRREF) [ten] = arr; Arrref refers to an array containing 10 integers

For Parray, it's not reasonable to read from right to left. Because the dimensions of an array are followed by the declared name, it is much better to read from the inside than from right to left for an array.

The first is inside the parentheses, *parray means the parray is a pointer;

Next, on the right, Parray is a pointer to an array of size 10;

Finally, look to the left and know that the elements in the array are int.

1 int ia[5];
2 Auto Ia2 (IA); IA2 is an integer pointer
3 Decltype (IA) ia3; IA3 is an array that contains 10 integers

C++11 new features: standard library function begin () and end ()
To make the pointers more secure and simpler to compute, the new C++11 standard introduces two functions named Begin and end, which are used to compute the iterator of the array.

How multidimensional arrays are accessed

 1     int ia[3][4];
 2     for (auto P = ia; p!= ia + 3; ++p)
 3     {
 4          for (Auto q = *p q!= *p + 4; ++q)
 5    & nbsp;    {
 6            // Do something
 7        }
 8    }
 9
10     for (auto P = Begin (IA), p!= End (IA); ++p)
11     { br> 12         for (auto q = Begin (*p), Q!= End (*p); ++q)
13  &nbs p;      {
14             //do something
15        }
16    }

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.