Programmer exam remedial note - the ninth day

zhaozj2021-02-16  47

Today, I finally arrived in the core part of the C language. The pointer has always been a big focus of learning C language. If we don't learn a C language pointer, then we can say that there is no C language. . But then, when I first started to contact C, the basic syntax of the front is very fast, but I learned that the pointer is stupid in the array. Because I don't know why there are so many array calls. (Binding to the pointer). In fact, I'm very difficult to understand the guy. Please ask you to debug a lot of debugging. After adding the experience, look back and look at the chapter of the pointer, I believe it can also touch it. Because I also came over, I also read a lot of source program using pointers.

Now we start with a relatively simple one-dimensional array relative to the two-dimensional array, first look at how to define a pointer to the one-dimensional array.

INT A [5] = {1, 2, 3, 4, 5};

INT * P;

P = a; / * Here A is because it is a group of variable names, its value is the first address of this array * /

Follow we can change the value of the array through the pointer

P ;

* p = 6; / * The second element of the array is equal to 6 * /

Here is the way to move the pointer down, and this point points to the second element of the array. Let's take a look at its address, through this pointer, the address of the current pointing element. Then how the address is running? The P this command is to move down. If you follow the type of array A, the array A is an integer, the space is two bytes, and the p is only 1, and the top is to the first In the last half of an element, can you point to the second element? In fact, here is the type when defining a pointer, we define the integer type here, "Yes, define the integer is right, because it wants to point to plastic data, then of course, it is necessary to define this type. "", In fact, this is not a real answer, and it is not necessary to define as the same type as the point to point, and we can define the type of pointer to other. For example, it is defined as float, but here is executing P directly skip a array element, then let's take a look at what is going on. In fact, our defined pointer type is used to combine a pointer to make a certain rules. Here, it can be seen that if it is the definition int type, you can go to the second element, indicating that P is not a simple address plus one, but first combines this type to make an operation, add once, equal to the address. 2. The Float moved 4 digits, so the combination obtained was moved to the third element.

Take another look:

A = a 1;

Here we perform address shift assignment, but this command is wrong, and the C language is a set of address constants, so it does not change its value.

Next, it is said that the two-dimensional array is, because our task today is to first figure out a one-dimensional number of groups first. Now let's first define a two-dimensional number of groups.

INT A [2] [4];

Here I no longer repeat the things in the book, I told the teacher to give us the kind of thought. Let's take a look at a two-dimensional array, which is a one-dimensional array of elements, so nested. Of course, the other multi-dimensional numbers are nestled in this way. Let's take a look at this picture as shown in the ninth day.

This is easy to explain why A [0] and & a [0] is the same representative address, in fact, it is just the first address, it is difficult to speak from text, but it can be understood in the sense. We act as a one-dimensional array of two-dimensional arrays, not to see it as two-dimensional, so draw it as follows:

a [1] [1];

Available as a one-dimensional M name

M [1]; / * Call the second element * /

We tried to see all this as, defined such a one-dimensional array INT A0 [4], A1 [4], A2 [4];

In this way, we know that A0, A1, A2 are the first address.

Ok, it may also be more blurred. If you don't understand, you will consider an array according to your original thoughts, because everyone has their own ideas and understanding.

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

New Post(0)