In-depth exploration of the mysteries of C/C ++ arrays and pointers
This article is a revised version of the repeat pointer made by the author in 2005. Compared with the previous article, the main differences in this article are as follows:
I. Introduce the C/C ++ standard clause to describe the principle. C and C ++ standards have four official versions, c89/C90, c99, C ++ 98, and C ++ 2003. To avoid repeated clause references, in the case of the same text or semantics, I only reference the c99 clause and reference it separately in different situations.
2. Added C ++ content.
3. added or merged some chapters and corrected some incorrect texts.
Pointer is the soul of C/C ++! It is one of the many fascinating features of C/C ++. Being in close contact with underlying operations is inherent in pointers. Using pointers, you can write a lot of short, refined, and efficient data.Code. It is an irreplaceable tool for C/C ++. With this tool, C/C ++ is at least more efficient than other advanced languages. .
However, because the principle and usage of arrays and pointers are quite different from people's common habits of thinking, it takes a lot of time to digest them, this makes the prejudice and misunderstanding of arrays and pointers a common phenomenon, but also avoids the use of pointers. I think this is very undesirable. The pointer is so sharp that it makes the C/C ++ language extremely powerful. If you give up on it in this way, then C/C ++ is even a matter of white learning. We should make the pointer your hand the holy sword of nasil, which has cut suo Lun's finger on the Lord of the Rings, rather than the Eternal Lord of the Rings in your heart. .
Like many beginners, my understanding of arrays and pointers has gone through a long process. When I was a beginner at C, I was one of the victims of Tan shu. Like other beginners, my head was filled with various misunderstandings about arrays and pointers. Later, with the in-depth understanding of C/C ++, I gradually found a large number of errors and vulnerabilities in Tan's book, and started the course of correction. This is a painful and happy process. It is because the resentment has been murdered for a precious period of time. Happiness is because we have found a new direction. I believe many of my friends have had similar experiences with me. During this period, I consulted a lot of materials and spent a lot of time thinking deeply. I also had a lot of debates with colleagues, friends, and netizens, especially in 2005, I spent almost a whole year in a heated debate. I still remember the intensity of these debates. If I had a gun in my hand, I thought I would have shot it! The fog of arrays and pointers gradually becomes clearer after constant thinking, debate, validation, and further reflection.
The purpose of this article is I hope to discuss several key concepts and frequently asked questions about arrays and pointers with my friends to deepen my understanding of arrays and pointers. . I do not expect to be able to completely unlock the magic knot in your mind, but if you read this article, you will be satisfied if you reduce mistakes in the future use of arrays and pointers.
After reading this article:
If you have different opinions, you are welcome to leave your own opinions in the comments. I am happy to discuss with you and make progress together.
If you think everything I said is nonsense, congratulations! Your Pointer has graduated.
If you have too many things you don't understand, let me introduce you first to read some books about arrays and pointers. I recommend you read a book called C and pointers, come back and continue to think about your problem.
Original article: http://blog.csdn.net/supermegaboy/archive/2009/11/23/4855036.aspx.