Pointer to a one-dimensional array char (*P) [10];
Pointer to a one-dimensional array of type typedef char (*type_p2array) [10];
The pointer can point to an array, and the effect is the same, but pointers and arrays are not equivalent. {sizeof results are different, and the pointer can also point to other types of data. }
#include <stdio.h>typedef int (*tp_parry1) [3]; #define UART_PRINTF printfvoid F1 (void) {int a[2][3] = {{0,1,2},{ 10,11,12}};//A: Two-dimensional array name, equal: pointer to one-dimensional array {0,1,2} tp_parry1 p = A; int (*Q) [3] = A; int (*t) [2] = a;//warning:initialization from incompatible pointer type//int** x = A; CRITICAL ERROR, may leads to segmentation fault. NO space for Ptrs. Pointer binding law: 1 (*Q) parentheses highest priority, indicating that q is a pointer. 2 Right [], means pointing to an array//3 to the right no, to the left, the element that represents the array is of type int. uart_printf ("a00:%d\n", a[0][0]); uart_printf ("a01:%d\n", a[0][1]); uart_printf ("a02:%d\n", a[0][2]); uart_printf ("a10:%d\n", a[1][0]); uart_printf ("a11:%d\n", a[1][1]); uart_printf ("a12:%d\n", a[1][2]); uart_printf ("p00:%d\n", a[0][0]); uart_printf ("p01:%d\n", a[0][1]); uart_printf ("p02:%d\n", a[0][2]); uart_printf ("p10:%d\n", a[1][0]); uart_printf ("p11:%d\n", a[1][1]); uart_printf ("p12:%d\n", a[1][2]); uart_printf ("q00:%d\n", a[0][0]); uart_printf ("q01:%d\n ", a[0][1]); uart_printf ("q02:%d\n", a[0][2]); uart_printf ("q10:%d\n", a[1][0]); uart_printf ("q11:%d\n", a[1][1]); uart_printf ("q12:%d\n", a[1][2]); #if 0//segmentation fault uart_printf ("x00:%d\n", x[0][0]); uart_printf ("x01:%d\n", x[0][1]); uart_printf ("x02:%d\n", x[0][2]); uart_printf ("x10:%d\n", x[1][0]); uart_printf ("x11:%d\n", x[1][1]); uart_printf ("x12:%d\n", x[1][2]); #endif}int Main () {F1 ();} /*[email protected]:/work/dcc# gcc *.c;./a.outa00:0a01:1a02:2a10:10a11:11a12:12p00:0p01:1p02:2p10:10p11 : 11p12:12q00:0q01:1q02:2q10:10q11:11q12:12*/
Two-dimensional array (the relationship between the array name and the address)
First define a two-dimensional array and a pointer to it p_array:
Char array[3][1000];
typedef char CHAR_ARRY2[3][1000]; typedef char_arry2* PCHAR_ARRY2; Pchar_arry2
P_array= &array;
| Decimal Absolute Address |
Point to Element |
Point to a one-dimensional array |
Point to a one-dimensional array |
Point to a one-dimensional array |
Point to a two-dimensional array |
Hex Address |
| 872369208 |
ARRAY[0] |
&ARRAY[0] |
Array |
P_ARRAY[0] |
P_array |
33ff4c38 |
| 872369209 |
Array[0]+1 |
|
|
|
|
33ff4c39 |
| .... |
|
|
|
|
|
|
| 872370208 |
|
&array[0]+1 |
Array+1 |
P_array[0]+1 |
|
33ff5020 |
| ... |
|
|
|
|
|
|
| 872372208 |
|
|
|
|
P_array+1 |
33ff57f0 |
array = =
&array[0]
Pointers and arrays--pointers and two-dimensional arrays 2