Memory Model of level 2 pointer
First memory model of level 2 pointer |
Char * Accary [] = {"aaaaaa", "bbbbbb", "ccccccc "}; // Method of using the interface parameters Intprintfarr (char ** ArrayStr, int iNUm) { For (I = 0; I <iNUm; I ++) {
Printf ("% s \ n", ArrayStr [I]); } } // Call method Printfarr (Accary, 3 ); |
Second-level pointer memory model |
CharArray [10] [30] = {"aaaa", "bbbb", "cccccc ",};
// Method of using the interface parameters Voidabc (char Arrary [30], 4) { For (I = 0; I <4; I ++) { Printf ("% s \ n", Accary [I]); } } // Call method Printfarr (Array, 3 ); |
Second-level pointer's third-minute memory model |
Char ** real = (char **) malloc (3 * sizeof (char *)); For (int I = 0; I <3; I ++) { Real [I] = (char *) malloc (30 * sizeof (char )); }
Sprintf (real [0], "dbsiudaudhakdhjhba "); Sprintf (real [1], "B "); Printf ("% s \ n", real [1]); // Method of using the interface parameters Intprintfarr (char ** ArrayStr, int iNUm) { For (I = 0; I <iNUm; I ++) {
Printf ("% s \ n", ArrayStr [I]); } } // Call method Printfarr (Accary, 3 );
|
Extension of parameter writing:
Voidstr (char abc [30]); Voidstr (char abc []); a one-dimensional array is used as a form parameter and degrades to a pointer. Voidstr (char abc); manually add * to manually complete the compiler task |
// For the second memory model Voidstr (char abc [30] [60]); Voidstr (char abc [] [60]); a two-dimensional array is used as a form parameter, which is degraded to a pointer and 60 as a pointer step. Voidstr (char (* abc) [60]); manually add * to manually complete the compiler task, which is actually an array pointer |
Equivalence relationship
Array parameter equivalent pointer parameter
One-dimensional array chara [30] -----------------------------> pointer char X Pointer array char X a [30] --------------------------------> pointer char X Two-digit array chara [30] [30] ------------------------------> array pointer char (× a) [30] |
Three memory models of level 2 pointers