The array type and array pointer type in the C language.

zhaozj2021-02-16  70

#include using namespace std;

INT main () {// Wait long two-dimensional array: int aint2darrayonstack [2] [8]; int * PintArray = aint2darrayonstack [0]; // int * == int []; int (* pint2daRray) [8] = aint2darrayonstack; // int (*) [8] == int [] [8]

// With the above experience, you can understand. Int (* PINT2D) [8] = new int [2] [8]; int * Pint = * Pint2D; // * Pint2D = int [8] int = INT AINT = ** PINT2D; // ** pint2d = int [0] [0]

// The following will be practiced when the COUT << SizeOf (aint2darrayonstack) << Endl; cout << sizeof (PINT2D) << Endl; cout << sizeof (* PINT2D) << endl; cout << sizeof (PINT2D [0] << Endl; cout << sizeof (** PINT2D) << ENDL;

Return 0;}

/ * The key here is probably the type: Who knows what is the difference between the following types? INTINT * INT [] int (*) [] int * [] int ** int [] []

The pointer type is: int * int [] int (*) [] int **

Its length is 4, which can be automatically converted is int * and int []. Because the array has the nature of the pointer.

It can be forced to convert int * <=> INT (*) [] and int [] <== INT (*) [] Because the two-dimensional array is essentially one dimension.

INT ** is a pointer to the pointer, which is completely unhappy with the above type.

Array types are: int [] int * [] int [] []

They are all arguments, the length is related to its elements. Assumption type is: int [n] int * [n] int [n] [n]

Then INT [n] and int * [n] are 4 * n, they are all one-dimensional array, the former is a one-dimensional INT array, the latter is a one-dimensional INT * array. And int [n] [N ] Is N * n * 4, which is a two-dimensional array.

How to define the pointer to the two-dimensional array? Is int (*) [n] [n] or int (*) [n];

Also practice. * /

转载请注明原文地址:https://www.9cbs.com/read-15632.html

New Post(0)