數組指針是一個指針,只對應類型的數組。指針數組是一個數組,其中每一個元素都是指針
數組指針遵循指針運算法則。指針數組擁有c語言數組的各類特性算法
C 經過 typedef 爲數組類型 重命名數組
**格式 : **typedef type (name)[size]指針
typedef int (aint)[10]; typedef float (afloat)[10];
aint iarray; //定義了一個數組 afloat farray; //定義了一個數組
typedef int (*Paint)[10]; typedef float (*Pafloat)[10];
type(*pointer)[n]; //pointer 是一個指針,type表明指向的數組的類型,n爲指向的數組的大小。
例:code
#include <stdio.h> typedef int (aint)[10]; //定義一個數組類型 typedef int (*Paint)[10]; //定義一個指針數組類型 int main() { int a[10] = {0}; aint myarr; myarr[0] = 8; printf("%d\n", myarr[0]); Paint Pmyarr; Pmyarr = &a; (*Pmyarr)[0] = 10; printf("%d\n", a[0]); int (*pointer)[10]; //定義一個指向數組類型的指針 pointer = &a; (*pointer)[0] = 20; printf("%d\n", a[0]); }