#include <stdio.h>
int main()
{
int arr[5] = {10, 20, 30, 40, 50};
int arr1[5] = {11, 21, 30, 40, 50};
int(*ptr)[5] = &arr;
printf("arr+1=%p,%d\n", arr + 1,*(arr + 1));
// &arr代表整个内存空间地址,加1代表向前移动一倍的内存空间
//*(&arr + 1) 非法了,类似越界
printf("&arr+1=%p,%d\n", &arr + 1,*(&arr + 1));
printf("arr+1=%p \n", arr + 1);
// 如果没有声明指针数组的大小,ptr + 1则会显示报错,因为它不知道加1要走多少字节
printf("ptr+1=%p \n", ptr + 1); // 对于这个指针数组来说,加1会导致它向前移动一倍的内存空间
// 使用数组指针遍历数组
for (int i = 0; i < 5; i++)
{
printf("%d \n", (*ptr)[i]);
printf("%d \n", *(*ptr+i));
}
ptr = &arr1;
for (int i = 0; i < 5; i++)
{
printf("%d \n", (*ptr)[i]);
printf("%d \n", *(*ptr + i));
}
/*数组和数组指针的区别
1.类型不同 int [] int (*)[]
2.数组的指向不能改变,数组指针可以改变指向
arr = arr2 ptr = &arr1;
3.数组名不需要显式初始化,数组指针需要显示初始化,不然不知道指向哪里
4.数组名不需要解引用,而数组指针需要解引用才能访问数据*/
return 0;
}
01-04
6260
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-08
8658
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-07
2102
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-02
1045
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)