<C++ Primer_5th>习题_3.35

来源:互联网 发布:ubuntu修改hosts翻墙 编辑:程序博客网 时间:2024/06/05 20:44
//编写一段程序,利用指针将数组中的元素置为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;}

原创粉丝点击