Joke Collection Website - Joke collection - It's just that there is something wrong with the pointer array in C language.

It's just that there is something wrong with the pointer array in C language.

int a[4][ 10],*p,* q[4];

Type of A: int [4][ 10], A is a one-dimensional array with four elements, and each element is a one-dimensional array with 10 int data.

Essentially, C language has no multidimensional arrays! Please remember.

So the first element of A is a[0], and A is the address of the first element a[0], that is, A = &;; a[0]

Never think that A is the address of the first element a[0][0], but write it as A = &;; A [0][0], joke!

Remember: the first element of A is a[0], so you won't be confused when you learn multidimensional arrays and pointers in the future!

Type of p: int *

Type of q: int *[4]

Look again, what type is a[i]? Very simple, int [10]! One-dimensional array!

What about q[i] Int *?

Here comes the point: why does q[i] = a[i]? Don't you get it? !

(Disclaimer: The following is my personal original analysis method, original and ugly! )

In fact, if we look at the definitions of one-dimensional array and one-dimensional pointer, you will understand.

int A[ 10];

int * Q;

q = A; & gt& gt& gt understand? Bit arrays can be assigned to one-dimensional pointers. (only one dimension! )

But multi-bit arrays cannot be assigned to multi-bit pointers, remember!

Look at our question again: q[i] = a[i]?

Because (a[i]) is a one-dimensional array (parenthesis is because a[i] is a whole, remember: A is a so-called two-dimensional array! );

And the type of (q[i]) (also the whole) is int *, which is a pointer. So both can be allocated!

To sum up: find the type method and remove the name!

For array, remove int a[4][ 10], the type of a, and the name int [4] [10]; Type a[i], get int [10] by removing a[i]!

For the pointer, it is actually the same.