本文共 316 字,大约阅读时间需要 1 分钟。
关键点:拿到数组首地址。
#includeusing namespace std;int main() { int arr[] = { 1,2,3,4,5,6,7,8,9,10 }; int *p = arr;//数组名就是数组首地址 cout << "第一个元素:" << arr[0] << endl;//1 cout << "指针访问第一个元素:" << *p << endl;//1 /* 利用指针遍历数组 */ for (int i = 0; i < 10; i++) { cout << *p << endl; p++; } system("pause"); return 0;}
结果展示:
转载地址:http://lyxq.baihongyu.com/