Note range: 2.1 to 2.2
Many people will find the second chapter difficult. The author also mentioned in the first article that if the reader finds the content in the second chapter hard to be understood, he should be skipped. I personally think that this is not the best choice. In fact, the purpose of the first article is to have a good overall understanding of the language and the habits of thinking, the formation of methodology is the focus of this chapter. The above nonsense is a simple description and suggestion of the difficulties we will face and the attitudes we will adopt,
The things we learned in Chapter 1 are relatively ready-made and can be used directly. They are not subject to syntax restrictions during use, I think you still remember that when I read the data type, I had a question: Why didn't the author mention arrays at that time? In section 2.1, the author gives an answer: arrays do not belong to the basic type. What is the basic type? The author explains that the language itself provides built-in support for this type of assignment, General Arithmetic Operations, and relational operations. Obviously, arrays and pointers cannot meet this condition. According to the author, they are not first-class citizens,
Knowledge about these two sections. I don't want to talk much about it. For those who have learned a little programming, arrays and pointers are nothing new. In the preface of this book, the author said, "This book is suitable for C ++ beginners, but not Programming beginners." However, there are still two low-level errors that many beginners may make:
Array: Here is an example:
Int A [8];.
A [8] = 10;
These two 8 s are almost identical. The fact is: the meaning and function are completely different. The former is size and the latter is subscript. Here I have to have a question: [] What is the operator? For the first time, we have seen a multi-use example (maybe not, let alone ).
Pointer. I have seen many usage similar to this:
Int * P = NULL;
Cout <* P <Endl;
Obviously, a qualified programmer will not write such code, but it is not a friend's reminder. I think it can only be a dumb error. Here there are two problems: What is null? I used to naively associate it with ASCII, in fact. It is 0. Assign a value of P to an integer. The next step is space allocation. We all know that null is used to prevent pointers from pointing to any space useful to the program. So what about 0? Obviously, there is a misunderstanding about space, that is, the pointer space is different from the pointer space. The pointer space is allocated when it is defined, but it can only put the memory address and null (P), pointing to the space in the container (* P), obviously, the above * P does not actually exist. It is of course impossible to get something that does not exist.
The author talks about new here. I have been a little scared about new for a long time. He is far less familiar with C functions. The author tells us that it is an operator for dynamically allocating memory. However, please note the author's explanation of Dynamic Allocation: "behavior of library functions at runtime ". Library function? No operator? Here we almost feel that there is a certain relationship between functions and operators. Let's take a deeper look and think about the shortcomings of the array mentioned at the beginning. Can't some operations be performed on arrays? Well, if our assumptions are true and there is a link between functions and operators, can we improve our array by ourselves? Facts prove that we are correct. This leads to the idea of ADT-class design (the subsequent content is a process of continuous design and perfection ). It can be seen that there is a big problem in our previous learning methods. We don't know why we want to learn something. The author has hinted at our answers. Requirements inspire, inspiration drives design, design achievements, and technology to lead to learning. Learning to meet requirements