LeetCode 3-22

基于范围的for循环(C++11)
for 语句允许简单的范围迭代

int my_array[5] = {1, 2, 3, 4, 5};
// 每个数组元素乘于 2
for (int &x : my_array)
{
    x *= 2;
    cout << x << endl;  
}
// auto 类型也是 C++11 新标准中的,用来自动获取变量的类型
for (auto &x : my_array) {
    x *= 2;
    cout << x << endl;  
}:
posted @ 2019-03-22 17:17  JokerMan  阅读(147)  评论(0编辑  收藏  举报