17. Pointer arrays and array pointers

Pointer array: The array of elements is a pointer.

Array pointer: Pointer to the array.

 

// Variable length string array, save the first address of each string, the string content is saved in the read-only area

// Combining the pointer as an element of the array can make the storage more compact, which can bring access advantages

const char *pszBuff[] = {

"wqerasdf",

"wqe4f",

"wqwertd2324f",

"23f",

};

 

// A fixed-length string array, each element takes up 32 bytes

char szBuff[][32] = {

"wqerasdf",

"wqe4f",

"wqwertd2324f",

"23f",

};

 

[Array name] is a pointer constant of type [Array 0th element].

The elements of [two-dimensional array] are [one-dimensional array]

Do * operation on [pointer of a certain type] to get a reference to [a type]

 

[SzBuff] is a pointer constant of type [char [32]].

The element of [szBuff] is [char [32]]

* szBuff, get the reference of [char [32]]

In other words, * szBuff gets a reference to a one-dimensional array

In other words, * szBuff is a pointer constant of type char
** szBuff gets a reference to char

 

 

int a[3];

a is a pointer constant pointing to the 0th element of the array, so it is int *

Take the address of the int variable and get int *

Take the address of the float variable and get float *

Get the address of the array type to get the array *

So take the address of a, which is & a, get int (*) [3]

 

 

 

 

The main points of pointer arithmetic:

What type of pointer participates in the operation

How to calculate

What type do you get after the operation

 

 

Guess you like

Origin www.cnblogs.com/Nutshelln/p/12758384.html