"C ++ Primer" reading note 5

zhaozj2021-02-16  70

Note: 2.1 Section to 2.2

Many people feel that the second chapter is difficult. The author also mentioned in the introduction of the first article: If the reader feels that the content of the second chapter is difficult to understand, he jumps out. And individual thinking is not the best choice, in fact, the first purpose is that there is a good overall understanding of this language, the habit of thinking, the formation of methodology is the focus of this chapter, in front of these nonsense, It is a simple explanation and suggestion for the difficulty we have to face and what we have to take.

Those things we are in the first chapter are more ready, can be used directly. It is not very limited by the syntax in the process of using it. I think everyone will remember that I am reading the data type. Have a question: Why did the author don't say arrays? In Section 2.1, the author gives an answer: arrays do not belong to basic types, what is the basic type? The author's explanation is that the language itself provides built-in support for this type of assignment, general arithmetic operation and relationship operation. Obviously array and pointers can not meet this condition, according to the author's original: they are not a first-class citizen,

About the knowledge points of these two sections. I don't want to say, there are not many, and those who have learned a few programs and pointers are not strange things. The author said in the preface of this book "This book is suitable for C beginners, but it is not suitable for the programming", but there are still two many initiaters who will commit to the low-level mistakes:

Array: I will give an example:

Int a [8] ;.

a [8] = 10;

These two 8 are almost identical. The fact is: in terms of meaning, the role is completely two things, the former is size, the latter is a subscript, here I have to produce a question: [] What is the operator? Here we have seen an example in which a consensus is used almost the first time (maybe not, just think so).

Pointer. I have seen a lot of usage similar to this:

INT * P = NULL;

COUT << * P << endl;

Obviously, a qualified programmer does not write such a code, but is not a friend's reminder. I also think that it thinks it can only be a fool error, there are two questions here: NULL is? I really tried it and ASCII before, in fact. It is 0. For a value given to the value. Next is the problem of spatial allocation, we all know that NULL's role is not to point the pointer to any space useful for the program. So 0 put it? Obviously, there is a misunderstanding of space, that is, the space of the pointer and the space pointing to the pointer is different. The space of the pointer is defined, but it can only place memory address and NULL (P), pointing space is something (* P) ​​in the container, obviously, the above * P does not exist. Take a thing that does not exist, of course, you can't do it.

转载请注明原文地址:https://www.9cbs.com/read-16079.html

New Post(0)