C language type of a two-dimensional array, & a, & a [0], a [0] [0] and the value of the value

The value and significance of the two-dimensional array c language in some expressions of problems


Two days before writing the code when it came to questions about the array, and then a two-dimensional array of some deep thinking. I think of an interesting question.

In the two-dimensional array a, & a, & a [0], & a [0] [0] output values ​​are the same meaning it represents Why does not the same?Here Insert Picture Description

Here to explain & a, & a [0], & a [0] [0] their meaning, & a represents the address of the entire two-dimensional array, & a [0] represents the address of a two-dimensional array of the first line, & a [ 0] [0] represents the first line of a two-dimensional array address first element, then why their values ​​are the same, but the meaning they express it, but he is not the same?

In practice these values are not identical, they are just the same in value, they are completely different types, like for example with a type of int char type 1 is completely different.
In order to explain the different values of their type, we take an example will be described.

Here Insert Picture Description
It can be seen from the figure, although the values of these three expressions are the same in value, but after they were +1 for calculation, the resulting value is completely different.
We know that the pointer is a value variable address, so we can put these values that are pointer values, and & a + 1, & a [ 0] + 1, & a [0] [0] +1 may be considered as a pointer for plus one operation. Pointer plus one arithmetic rule is to add a pointer value of the pointer variable in the unit, there is such an array of int pointer p pointing to the first element of this array, the value of pointer p is the address of the first array of variable int , the p + int result is the address of the second array of variable 1.
Let us explain a knowledge, one-dimensional array malloc some memory can then be assigned to a pointer to achieve, and a two-dimensional array can be achieved in two ways pointer is a pointer to a pointer to two, more than a pointer pointing one element. Therefore, we can pointer the way to understand the array.

&a

A is a two-dimensional array, it can be understood as a pointer to a two, and the two & a is the pointer address, may be understood as a pointer to a value that is three pointers. Thus the above-described type further example & a value of int ***, it refers to the type of the variable int **, so & a + 1 is the next address int **, i.e. the address after the entire two-dimensional array.

&a[0]

The same, a [0] is the first line of a two-dimensional array, can be understood as a pointer to one, so & a [0] is a pointer to the value of its two pointers, the type & a [0] value is int **, the variable type is referred to int *, so & a [0] +1 int * is the next address, i.e. the address of the second row of the two-dimensional array.

&a[0][0]

a [0] [0] is an int type element, & a [0] [0] is a pointer to it a pointer value, & a [0] [0] value is of type int *, referring to variables types are int, & a [0] [0] +1 is the next int address, i.e. the first row address of the second two-dimensional array variables.

This article explain this issue to stop here, for some errors that may exist, to welcome all readers pointed out.

Released four original articles · won praise 3 · Views 180

Guess you like

Origin blog.csdn.net/humblehunger/article/details/103549535