–
代表二维数组的首地址,第0行的地址
n
a+i
代表第i行的地址
–
n
*(a+i) 即 a[i]
代表第i行第0列的地址
–
n
*(a+i)+j 即 a[i]+j
代表第i行第j列的地址
–
n
*(*(a+i)+j ) 即 a[i][j]
代表第i行第j列的元素
–
n
元素a[i][j]的地址的几种等价的引用方式
&a[i][j] – a[i]+j
–
*(a+i)+j
– &(*(a+i))[j]
–
n
元素a[i][j]的几种等价的引用方式
a[i][j] – *(a[i]+j) – *(*(a+i)+j)
– –
(*(a+i))[j]
n 二维数组的指针——列指针
int *p;
p = *a;//用列地址初始化
n 相对于数组起始地址的偏移量
– i*m+j
for (i=0; i n 二维数组的指针——行指针 int (*p)[3]; p = a;//用行地址初始化 for (i=0; i //指针数组 main() { int i; char *ptr[] {\"Pascal\ \"Java\ char **p; p = ptr; for (i=0; i<5; i++) { printf(\"%s\\n\ p++; = } } 动态分配内存 n 在 malloc(unsignedint size); 向系统申请大小为size的内存块,把首地址返回。如果申请不成功,返回NULL n – n void *calloc(unsigned int num, unsigned int size); – 向系统申请num个size大小的内存块,把首地址返回。如果申请不成功,返回NULL n void free(void* p); – 释放由malloc()和calloc()申请的内存块。p是指向此块的指针 一维动态数组 : #include int *p = NULL, n, i, sum; printf(\"Please enter array size:\"); scanf(\"%d\ p = (int *) malloc(n * sizeof (int)); if (p == NULL) { printf(\"No enough memory!\\n\"); exit(0); } printf(\"Please enter the score:\"); for (i=0; i sum = 0; for (i=0; i printf(\"aver = %d\\n\ free(p); } 二维动态数组 #include int *pScore = NULL, i, j, m, n, maxScore, row, col; printf(\"Please enter array size m,n:\"); scanf(\"%d,%d\ pScore = (int *) calloc(m*n, sizeof (int)); if (p == NULL) { printf(\"No enough memory!\\n\"); exit(0); } printf(\"Please enter the score:\"); for (i=0; i maxScore = FindMax(pScore, 3, 4, &row, &col); printf(\"maxScore = %d, class = %d, number = %d\\n\ maxScore, row+1, col+1); free(pScore); } 因篇幅问题不能全部显示,请点此查看更多更全内容