C++ for(auto a:b)、for(auto &a:b)、for(const auto &a:b)

b为数组或容器,是被遍历的对象

for(auto &a:b),循环体中修改a,b中对应内容也会修改

for(auto a:b),循环体中修改a,b中内容不受影响

for(const auto &a:b),a不可修改,用于只读取b中内容

posted on 2021-12-04 14:15  _rhythm  阅读(529)  评论(0)    收藏  举报