Summary of C ++ learning points (I)

Source: Internet
Author: User

C ++Summary:

1. When passing a pointer, we can use the pointer to modify the content it points externally. However, it is impossible to modify the object pointed to by the external pointer. For example, if an external pointer is passed to the function to allocate space, the pointer or pointer reference must be passed.

2. char carry [10] = {0}; the compiler will set all the other things to 0;

3. When the return value of the function is const, the returned item cannot be left after it is indicated with the same type;

4. const int * I; int const * I; int * const I; the first two functions are the same, indicating that the content that I points to remains unchanged; the last one indicates that the address that the Pointer Points to remains unchanged, but the content is variable.

5. const member functions in the class. It is defined as adding const after the prototype. Constant functions cannot modify any attributes of a class. But there are two ways to modify it.

A) {(myclass *) this-> member1 = values ;}

B) define a member as mutable to be modified by the constant function.

6. constants of the const type in the class cannot be used to define arrays in the class. The enum {ONE = 100; TWO = 2}; defined ONE and TWO are acceptable. In general, the allocation problem defined by enum is: enum A {L = 9, Z}; at this time, the value of Z is 10.

7. The int defined by const can be used to open up arrays. However, elements in the constant array defined by const cannot be used to define arrays.

8. Use sizeof to calculate the space of the variable. If it is an array, return by actual space; constant string (actually a variable opened in the static memory area) sizeof returns a value greater than the actual length. If it is a pointer, only the size of the pointer type is returned regardless of the space it points. If sizeof is used to calculate the row parameter of the function, even the Group returns only the size of a pointer of the relevant type.

9. For example, int iarray [] = {12,124,433}; the compiler automatically assigns the length of three elements to the iarray. The formula for calculating the number of element lengths is sizeof (iarray)/sizeof (* iarray ).

10. copy constructor: When the row parameter and the real parameter are combined, if it is a value transfer type of a complex object, call the copy constructor to generate a temporary object as the real parameter and exit the function, the temporary object is released by calling the destructor. When the returned value is a complex object, it also calls the copy constructor to assign values. In this case, the number of calls of constructor and destructor is not equal. The prototype of the copy constructor is A (A &), which can be reloaded in the class. (The default copy constructor uses the bit COPY method: the shallow COPY method does not copy the content pointed to by the pointer ).

11. volatile variables tell the compiler that code optimization is not required for this variable. In multi-threaded applications, if we read a variable into the register, the time slice will expire and process other threads. When the processor is re-acquired, the volatile type will tell the processor, instead of directly processing the register data, you can re-read the data from the variable to the Register to prevent dirty data.

12. The class and struct have the same functions to a certain extent, except that the default members of the former are private, while those of the latter have a common lack of time-saving members. Therefore, class is not a required reserved word for c ++.

13. the c and c ++ compilers generate different identifiers for the same function name after compilation. Therefore, when referencing the c library file, you must use the extern "C" to tell the compiler, it is a c function that is compiled according to the c Rules. The standard header file we use has been processed.

14. # include "filename"; # include The former searches for files in the current directory. If the files cannot be found, the former searches for files in the path specified by the system. The latter searches for files in the path specified by the system.

15. static variables allocated anywhere have the same lifecycle as the primary process. The second definition of an existing static variable has no effect on the use of the variable, but its visible range is only within the defined range. (It is not difficult to understand the characteristics of static variables. The static type in the class is shared by all objects)

This article is not complete. You are welcome to continue reading the C ++ learning points in the second half ).

  1. Pointer usage in C ++
  2. How to become a C ++ programmer
  3. Common c ++ programming tools
  4. 50 tips for C ++ beginners
  5. The 20 most basic rules of c ++

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.