#include <stdio.h>
//巩固知识:
// *是取值运算符和声明指针类型
// &是取地址运算符
//C语言多维数组与数组指针
int main() {
int a[5][10] = {
{0,1,2,3,4,5,6,7,8,9},
{10,11,12,13,14,15,16,17,18,19},
{20,21,22,23,24,25,26,27,28,29},
{30,31,32,33,34,35,36,37,38,39},
{40,41,42,43,44,45,46,47,48,49}
};
//定义多维数组的指针需要在括号()中定义否则会认为是指针的数组,但这是数组的指针
int(*a1)[10] = a;//定义一个指针为*a1指向数组a的某个数组,数组内有[10]个元素,[10]的每个元素都是指针指向了整型数值
printf("a1=%d\n", a1);
printf("a1+1=%d\n", a1 + 1);
printf("a1+2=%d\n", a1 + 2);
printf("a1+3=%d\n", a1 + 3);
printf("a1+4=%d\n\n", a1 + 4);
//提示:a[5][10]相当于,a[有5行][每一行都有10列]
int* a2 = *a1;//a1指向当前行的首个列的元素,a2指向当前列的首个列的元素
printf("a2=%d\n", *a2);
printf("a2+1=%d\n", *(a2 + 1));
printf("a2+2=%d\n", *(a2 + 2));
printf("a2+3=%d\n", *(a2 + 3));
printf("a2+4=%d\n", *(a2 + 4));
printf("a2+5=%d\n", *(a2 + 5));
printf("a2+6=%d\n", *(a2 + 6));
printf("a2+7=%d\n", *(a2 + 7));
printf("a2+8=%d\n", *(a2 + 8));
printf("a2+9=%d\n\n", *(a2 + 9));
int* a3 = *(a1 + 1);//a1指向当前行的首个列的元素,a3指向当前列的首个列的元素
printf("a2=%d\n", *a3);
printf("a2+1=%d\n", *(a3 + 1));
printf("a2+2=%d\n", *(a3 + 2));
printf("a2+3=%d\n", *(a3 + 3));
printf("a2+4=%d\n", *(a3 + 4));
printf("a2+5=%d\n", *(a3 + 5));
printf("a2+6=%d\n", *(a3 + 6));
printf("a2+7=%d\n", *(a3 + 7));
printf("a2+8=%d\n", *(a3 + 8));
printf("a2+9=%d\n\n", *(a3 + 9));
}
笔者写到这里,陷入了困境,因为暂时不知道如何写让人通俗易懂。
在这里邀请大家在评论区讨论,关于指针数组如何理解容易的问题,帮助笔者完成本文章。