Three memory models of level 2 pointers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.