Char a[10][100] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; Compile at compile time asChar (*) [100], which is a pointer to an arraychar (*C) [+];is the same as the type of a, which is a pointer to an array. Has a definite dimension, or it can be thought of as the length of the object pointed to by the pointer. in-memory storage form
C + + each time the first address of an array is removed
Char **d;This is a pointer to the pointer,in-memory storage form
d++ every time. The address of a pointer to a two-dimensional array and pointers to pointers can not be used directly, the difference is in the form of memory,
char** that the memory is a continuous pointer, char (*) [100] is considered a continuous array in memory, the interpretation of memory is not the same, char** will be char (*) [100] The value of the array is interpreted as an address, and char (*) [100] will char** The address is interpreted as a value. Of course it's wrong. char** and Char (*) [100] How to convert each other. Method 1:char A[10][100] = {0};char *p[10];for (int i = 0; i<10; i++) { P[i] = a[i];} char **p2 = p; The first address of an array of two-dimensional arrays is saved with an array pointing to pointers, and the array pointing to the pointer is the same type as the pointer pointer. Method 2:char A[10][100] = {0};char** P1 = (char**) A;char (*P2) [+] = (char (*) [[]]) P1; A pointer to a pointer that is strongly converted to a pointer to an array at the point where it was called, Used after recovery type. Method 2 is not as common as Method 1, and if a changes the definition and P2 does not have a corresponding change, it will cause an implicit error. Methods for passing multidimensional arrays as parameters to a function: Method 1 and Method 2 common methods 3: pass multidimensional arrays as parameter methods 4: pass pointers to arrays as arguments, as previously said, pointers to arrays and two-dimensional arrays are the same type. Netizen's section code #include "stdafx.h" #include <iostream> using namespace std; Int _tmain (int argc, _tchar* argv[]) { int arr1[3]; int arr2[3]; int arr3[3]; &NBSP;&NBSP;&NBSP;INT&NBSP;*&NBSP;PTR;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//&NBSP;PTR1 is a point to int [3]The pointer, the type of PTR and the type of &ARR1, is the same, note: arr1 points to the memory area fixed length int ptr1[3][3]={{1,2,3}, {1,2,3},{1,2,3}};&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//&NBSP;PTR2 is a pointer to int * , which is the type of PTR2 and & PTR is the same, note: PTR points to an indefinite length of memory area int * ptr2[3]={arr1,arr2,arr3}; &NBSP;&NBSP;&NBSP;//&NBSP;PTR3 is a pointer to int [3] , that is, the type of PTR3 is the same as the type of &ARR1, note: arr1 points to the memory area fixed length int (*&NBSP;PTR3) [3]=&arr1; ptr3=ptr1; // Yes, they are the same type // ptr3=ptr2;//error cannot be converted from "int *[3" to "int (*) [3] // &NBSP;PTR4 is a pointer to int * , that is, the type of PTR4 is the same as the &ptr, note: The memory area that PTR points to is indefinite length int ** ptr4; //ptr4=&arr1; //error cannot be from "int (*) [3]" Convert to "int ** ptr4=ptr2; // Yes, they are the same type //ptr4=ptr3; / / error cannot get from "Int (*) [3] "Convert to" INT&NBSP;**&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;RETURN&NBSP;0;&NBSP;
Two-dimensional arrays and pointers to pointers