From today, I will summarize the stage of a certain subject. Of course, these are all very light and will not be published in any column, just in order to prepare, the contents of this part is more in depth. This method is currently under experimentation, such as the effect is not ideal, should be adjusted at any time. These articles have not been divided into the order, just see where it is written, since it is written to himself, it will not be as strict in order.
In fact, the function part, the C language is really wonderful, and the previous tiled is here to see the fall. Of course, I have to say today is the pointer, and the reason why the function should be said before the function, because today's content is the pointer part. Since the part involving the argument of the pointer is more difficult, I completed the contents of the pointer. Today, I focus on some of the basic features of the pointer and complete his advanced part tomorrow.
Everyone will say when it comes to C, I want to learn good C language, so I have to learn good pointers. Before you didn't learn this language, it was unqualified to make an objection to this sentence, so I will unswervingly move forward in the direction of the predecessors. For pointers, it itself provides a powerful and flexible data manipulation, using pointers to complete some work, and some work will not be completed if the pointer is not used. If the function is built for the C language, the meaning of the pointer is that he maximizes all the order of the data type (especially arrays) running on this platform. The dynamic "maintenance" is more complicated than static "platform", which is also destined to pay more efforts than before learning his process. If the function gives a function, it is excited and praised, then the initial impression of the pointer is more confused.
We have a preliminary understanding of the C language, knowing that the variable is used to store data. In the memory of the PC, each memory unit has its unique memory address, which is not exposed to it. If you know the address of a variable, we can create another variable to store the address of the previous variable. Temporarily do not say this, in short, we now just understand, the pointer is also a variable, he is a variable used to store the address of another variable. Like "the variable that only stores the data", it makes sense only the pointer to the address stored.
The initialization of the pointer has always been a problem. Like variables, pointers follow the principles of "first defined". If you forget to define a pointer, the consequence will be very serious because the pointer stores an address of a certain variable, when you call an undefined pointer, he will generate an address and bring a program, this address is possible to point to A system program, if you are serious, you can make the system paralyzed.
Declaration of pointers: Typename * Pointer
Initialization: Pointer = & variable
The biggest use of the pointer is the manipulation of the array. I assume that we have a certain understanding of the knowledge. Of course, a pointer does not point to all elements in an array, so we let the pointer points to the head elements of the array, that is, the pointer is stored, which is the memory address of the first element in the array, and since the array is arranged in order Features, other array elements can find their location in memory. Array without parentheses is a pointer, such as the first address pointer of Data [], or it can be represented by & data [0].
In a sense, the pointer can replace a group of arrays, which is especially important when arrays as function parameters. Since the function only allows the single value and cannot be an array, the return value of the function is a pointer during the transfer of the function, which is the first address of the array, according to this first address, can thus recognize the address of each element in the array. Make the function to call the entire array. Then there is a problem: How to let functions know the length of the array called? There are two ways, one is that a special value can be stored in the last element of the array to mark the number of group lengths, but do this must set a reserved value at the end of the array, thus reducing the flexibility of storing data in an array. We generally adopt a second approach to deliver the array length as a parameter, which is more flexible and will not have any impact on the array itself. First write this, the first time I write about the program, I feel very tired. The reason is like this, or because of the unfamiliarity of the program itself, I hope that I can make me faster, I will be familiar with the program, tomorrow is a pointer (below), I hope to write smoothly and wonderful, see tomorrow .