Today, the two-dimensional array of days, let's see how the pointer to the two-dimensional array is. I want to repeat again before telling, if you understand the two-dimensional array, press you to understand. But more ways to think about it is also a good thing, then let's talk about it.
Now let's take a look at the two-dimensional number of pictures yesterday, the ninth day. We define a pointer to the two-dimensional number
INT A [3] [4];
INT * P;
P = a;
In fact, this also points to the pointer of the one-dimensional array, and the two-dimensional array is prioritized, and the line is a column order. We can use the pointer to guide the column, as follows:
P ;
We point here to the first column of the 0th line, then how can we go to the next line, in fact, the memory is assigned a series of continuous spaces to array when the memory is assigned, and we can move the pointer directly. When the last column of 0 rows was moved, the movement came to the first line. In fact, there is also a more wayward way in C language, see below:
INT (* p) [4] / * Here is a number pointer to define, and this pointer is pointers whose four elements with array * /
Let's take a look at this definition, * p Why must be parentheted, because [] This operator is higher than * priority, if it does not parenthe, it will become the most pointer, as for what pointers are in the most I will talk about it, now take a look at this pointer.
P = a;
P ; what will this be obtained? It is directly moved directly, this is the same as the reason that said the day before yesterday, is the combination of defined types to computers. We know how to move, so how do you move? This problem is more complicated, trying to move the pointer to the second column of Chain 1. Let's take a look at this expression, A 1 is the first address of the first line, the same P 1 is the first address of the first line. As for the column? First think about how the one-dimensional array moves to the column, it is the first address plus the order! Then we can express the first-dimensional array of first-dimensional array first, * (p 1) 2, see, does this point to the second column of the first line. We can not understand (P 1) is a line, from another meaning, it can be seen as the first address of the column (it is too difficult to understand, there is still a little clear, but I still want to use it back. Always understand the pointer, don't integrate, so it's too wrong.
I have said that I have another pointer, what is the other pointer, and the character pointer is relatively simple, but there are some special things. Let's take a look at some of the following programs:
Char * p;
P = "abc"; / * Here, since it is a string, it must be closed, this is different from the character array * /
Such assignments are ok, here is the first address of the string ABC to the pointer P, and then look at another program:
Char a [4];
a = "abc";
Is there a mistake here? For the C language, it is wrong because the character array A is a constant and cannot be assigned. Other advanced languages can be paid directly to it, then we want to assign ABC to the character array, there are several ways, one is a character assignment, one is to use the pointer, but here Or use the copy string function in the C language function library to complete strcpy (); everyone should have a function of this function, well, now give five minutes to do exercises, prepare a function of strcpy () . ............ Time is really fast, I will write it out.
Mycpy (Char * S1, Char * S2) {for (; * S1 = * S2 ;);
Ok, just in such a short two lines complete the replication function, this only C language can do.
Let's take a look at the following two programs.
Char * p, * q; char * p, * q, * r;
P = "abc"; r = "abc";
q = "abc"; p = R;
* q = 'd'; q = r;
Printf ("% s",% s ", p, q); * q = 'd';
Printf ("% s,% s", p, q);
What is the answer here? Think you think about it. Ok, I should have finished thinking, now give the correct answer, the first program is output ABC, DBC, and the second procedure is to output DBC, DBC. Why is this here? In fact, it is because the first program is pointing to the same address, that is of course the same value. Now there is a function pointer, in fact, we will never speak very much, but the teacher still tells us, and also puts a special place. We discover today, the procedure is as follows: int b = 0; int a [2] = {10, 20};
INT * AB (INT * P) {p ; return (p);} main () {b = * ab (a); / * Here we try to return the address that the call to the call is added, see You can point to that value, as for the result, we haven't tried it, I didn't have the machine when I wrote this diary. Everyone is interested. How is this problem? We first defined a pointer to the function, such as (* CD) (), we propose how it would be, because the brackets will be, because the original (* CD) () is a function to a returning pointer value, then We try * / printf ("% d", b);} Ok, today, today, there are still a lot of instructions, just I know that there are structural and common numerals can also be used in pointers, followed by other combined with linked lists, stacks, queues, and more. I think I just didn't have a little experience in this regard. I have seen the data structure and there is not much interest in it. Because I saw a lot of pointers have dizzy. However, in recent days, I will take a look at what I'm thinking, and I feel that I am not dizzy.