The two arrays in C ++ are used as function parameters.

Source: Internet
Author: User

The variable is declared in the scope as the type.

(1) The parameter is a two-dimensional array, but the dimension of the Second-dimensional must be specified.

Int array [10] [10];

Function declaration: void FUC (int A [] [10]);

Function call: FUC (array );

-- In function FUC, A is a two-dimensional array. Use a [I] [J] to access elements in the array.

(2) The parameter uses a one-dimensional pointer array.

Int * array [10];

For (I = 0; I <10; I ++)

Array [I] = new int [10];

Function declaration: void FUC (int * A [10]);

Function call: FUC (array );

-- In function FUC, A is a one-dimensional pointer array. Use * (a [I] + J) to access elements in the array.

(3) The parameter uses a pointer.

Int ** array;

Array = new int * [10];

For (I = 0; I <10; I ++)

Array [I] = new int [10];

Function declaration: void FUC (INT ** );

Function call: FUC (array );

-- In function FUC, A is a pointer. Use the * (int *) (a + I * D2 + J) form to access the elements in the array. Where:

A [0] <=> array [0] [0],

A [1] <=> array [0] [1],

...

A [10] <=> array [1] [0]

Note: D2 is the two-dimensional dimension of the Two-dimensional array, that is, the number of columns. And a + I * D2 + J is the address, so we need to forcibly convert the address of the pointer of this type to the pointer for use.

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.