1、通过指针修改数组元素的值
ps:int a[10] = {10}; 数组名a == &a[0] a+1 == &a[0]+1 跨过得是数组元素类型的长度,&a是对整个数组取地址,&a+1是跨过整个数组的长度
cpp
#include "stdio.h"
#include <stdlib.h>
int main()
{
int a[10] = { 0 };
int* p = a;
for (int i = 0; i < sizeof(a) / sizeof(a[0]);i++) {
//a[i] = i;
*(p+i) = i;
}
for (int i = 0; i < sizeof(a) / sizeof(a[0]);i++) {
printf("%d=%d\n",i,a[i]);
}
//数组{0,1,2,3,4,5,6,7,8,9}
system("pause");
return 0;
}