//编写一段程序,利用指针将数组中的元素置为0
#include<iostream>
using namespace std;
int main()
{
const int sz = 10;
int a[sz], i = 0;
//通过for循环为数组赋值
for (i = 0; i < sz; ++i)
a[i] = i;
cout << "初始状态下数组的内容是: " << endl;
//输出值
for (auto c : a)
cout << c << " ";
cout << endl;
//令p指向数组首元素
int *p = begin(a);
while (p != end(a))
{
*p = 0;
++p;
}
cout << "修改后的数组内容是: " << endl;
for (auto c : a)
cout << c << " ";
cout << endl;
system("pause");
return 0;
}
<C++ Primer_5th>习题_3.35
最新推荐文章于 2019-02-12 16:34:23 发布