Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the learning points of C++

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what are the learning points of C++". In the daily operation, I believe many people have doubts about the learning points of C++. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the questions about "what are the learning points of C++?" Next, please follow the editor to study!

1. When passing a pointer, we can use the pointer to modify what it points to on the outside. However, it is impossible to modify the object pointed to by the external pointer. For example, if you pass an external pointer to a function to allocate space, you must pass a pointer or a reference to the pointer.

2. Char carry [10] = {0}; the compiler will set everything after that to 0

3. When the return value of the function is const, the returned thing cannot be a left value after it is paid to a tag of the same type

4. Const int * i; int const * I; int * const I; the first two functions are the same, indicating that the content pointed to by I remains the same; * the address pointed to by the pointer remains the same, but the content is changeable.

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

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

B) defining a member as mutable can be modified by a constant function.

6. The constant const in a class cannot be used to define an array in a class. However, ONE and TWO defined by enum {ONE=100; TWO=2}; can. The usual allocation problem defined by enum is enum A {Lai 9, Z}, where Z has a value of 10.

7. Int defined in const can be used to open up arrays, but elements in constant arrays defined by const cannot be used to define arrays.

8. The space of the variable is calculated with sizeof, and if it is an array, it is returned by the actual space; the constant string (actually a variable opened in the static memory area) is returned by sizeof by one more than the actual length. If it is a pointer, it does not consider the size of the space it points to, but only returns the size of the pointer type. If you use sizeof to calculate the row parameters of a function, even if it belongs to a group, it only returns the size of a pointer of the related type.

9. Such as int iarray [] = {1224433}; the compiler automatically assigns the length of three elements to iarray. The formula for calculating the length of elements is sizeof (iarray) / sizeof (* iarray).

10. Copy constructor: when a row parameter is combined with an argument, if it is a value-passing type of a complex object, the copy constructor is called to generate a temporary object as an argument, and when exiting the function, the temporary object is called to release the destructor. When the return value is a complex object, the copy constructor is also called to assign the value. This results in a situation where the constructor and destructor are called unequally. The prototype of the copy constructor is A (A &), which we can overload in the class. The default copy constructor is to use the bit copy method: shallow copy, without copying what the pointer points to.

11. A variable of type volatile tells the compiler that this variable does not require code optimization. In multithreaded applications, if we read a variable into a register and the time slice expires to deal with other threads, when we reacquire the processor, the volatile type tells the processor to re-read the data from the variable to the register instead of processing it directly with the register data, which can prevent dirty data.

12. Class and struct have the same function to some extent, except that the default members of the former are private and the latter are common by default. Therefore, class is not a necessary reserved word for C++.

13. C and C++ compilers produce different tags for the same function names, so when referencing a library file of c, you must use extern "C" to tell the compiler that it is a function of c and compiles according to the rules of c. Usually the standard header files we use have been processed.

14. # include "filename"; # include, the former looks for files in the current directory first, and then looks for files under the path specified by the system if it cannot be found, and the latter looks directly under the path specified by the system.

15. Static variables (static) assigned anywhere have the same life cycle as the main process. The second definition of an existing static variable has no effect on the internal use of the variable, but its visible range is only within the defined range. (from the nature of static variables, it is not difficult to understand that the static type in the class is shared by all objects.)

At this point, the study of "what are the learning points of C++" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report