C | Three ways to access two-dimensional arrays: pointer variables, one-dimensional array Pointers, and two-dimensional array Pointers

The so-called two-dimensional array of C language is only a logical concept, physical storage is still one-dimensional, linear, and sequential storage.A logical two-dimensional array allows the associated Pointers to be moved by row or column, and the arithmetic of the internal Pointers is done by the compiler.C language array name is a special existence, the essence of which is a pointer with characteristics of constants, the address is the address of the first the storage unit, used for pointer offset (pointer or a pointer arithmetic) base address, in a different context, the array name with different types of information, so as to affect its arithmetic operations.1 and operator sizeof and & when used together, on behalf of the entire array space int arr [3] [4] =,1,2,3,4,5,6,7,8,9,10,11 {0};int size = sizeof arr / sizeof *arr; // In this context, arr is the address of the array, of type int(*)[3][4]funcD3(&arr,3,4);// In this context, arr is the address of the array, which is of type int(*)[3][4]2.FuncD2 (arr,3,4) represents the address of the 0th element (address of the first element of the array);/ / in this context, the arr is address, the first of the array whose type is int (*) [4] * (* (arr + I) + j) :The space of the ith row in the first column j * (* (arr + I) + j) – > * (arr [I] + j) – > arr [I] [j] these writing are set up, (* + I) (arr) [j] writing is correct.We know that to analyze a pointer, we must analyze the type of the pointer itself and the type of the pointer target.The addition or subtraction of a pointer to an integer constant, such as arr+ I, represents a movement of the pointer, resulting in a pointer of the same type.We know that expression operations require type consistency, otherwise implicit or explicit type conversions are required.The pointer is an address and an integer value. The target type of ARR is int[4], which determines that the number of bytes moved when it moves is the length of its target type, thus achieving consistency.*(arr+ I) is also a pointer that itself is of type int* and the target type is int(the target type refers to the type it points to or dereferences).Int arr[R][C], int*p, int(*ap)[C], int(*arr)[R][C]#include void funcD1(int *p,int r,int c){for(int I =0;i-End-

Leave a Reply

Your email address will not be published.