C + + Primer learning record (individual guess not beta version)

Source: Internet
Author: User

Learning version: Fifth Edition.

This post mainly records that the individual was unaware of the details of the knowledge.

Because the compilation environment under Linux has not yet been learned. So the actual code test will be completed in the future.

Red: Confirmation is required.

Blue: Focus.

1) The const object is set to be valid only within the file. personal opinion:. H. cpp belongs to the same file concept (not tested).

2) Constexpr: constant expression identifier. When used as a front/suffix, this variable/function is a constant expression. but, for specific purposes? And why do you need such identifiers?

3) do not add an element to an iterator whenever a loop using an iterator is used. Because adding elements can cause the container to reallocate memory, subsequent iterator operations may not be performed logically.

4) in the iterator loop, you can use the Delete (earse) operation. However, you need to be aware of the iterator execution. whenever possible, do not modify the iterator loop.

5)Auto does not add new content to C + + 11. Need to determine whether it is easy to use and code readability, and so on.

6) The initialization of an array must be a constant expression. Example: unsinged cnt = 42;  String bad[cnt]; An error, CNT is not a constant expression.

7) No assignment or copy of the array is allowed. (It should refer to an array of pointers, not arrays of contents.) )

8) Try to use the predecessor version (++I) when the data before the increment is not needed . Because the backend version needs to store the original data (the compiler is not usually optimized). Also applies to descending versions.

9) Bit operations are not used in signed data. The problem of uncertain results is easy to produce.

sizeof operator Three cases: P is a pointer, array_p is an array.

1,sizeof (P); Pointer size.

2,sizeof (*P); The size of the object pointed to by the pointer.

3,sizeof (array_p); The amount of memory occupied by the array.

  Note: An array is an exception to the case.

One) the const_cast can be converted between const and non-Const.

12) Each iteration of the iterator generated in the While condition section is also logged off (also created at the beginning).

The generic algorithm does not rely on containers (container operations are not performed), but relies on iterator operations.

14) before using the generic algorithm, the programmer needs to ensure that the container can accept the algorithm requirements. Example: Container size (algorithm fill).

A further understanding of the constant function characteristics is required.

C + + Primer learning record (individual guess not beta version)

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.