C++指针访问数组遍历
目录
1、注意点
int a[10] = { 1,2,3,4,5,6,7,8,9,10 };
int *p = a;
- 数组名字就是数组第一个元素的地址。
- 通过++p可以逐个访问数组元素
2、指针代码变量数组
#include<iostream>
using namespace std;
int main() {
//指针与数组
int a[10] = { 1,2,3,4,5,6,7,8,9,10 };
int *p = a;
for (int i = 0; i < size(a); i++)
{
cout << a[i] << " ";
cout << *p << " ";
cout << endl;
p++;
}
cout << endl;
system("pause");
return 0;
}
1
2
3
4
5
6
7
8
9
10
请按任意键继续. . .