for loopのシンタックスは for(statement1;statement2;statement3) だけだと思っていたのですが、以下のように使われているのを見て、混乱しています。この場合シンタックスはどうなっているのでしょうか?
また、for文の引数にconstをつけているのはどういった意図なのでしょうか?よろしくお願いいたします。
c++
1#include<iostream> 2#include<vector> 3using namespace std; 4 5int main() 6{ 7 //Declaration and initialization of vector 8 vector<int> num{ 1,2,3,4,5 }; 9 10 cout << "Initial elements "; 11 12 //this "for" is to display elements of vector 13 for(const int& i : num) 14 { 15 cout << i << ' '; 16 } 17 18 return 0; 19}

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/04/04 12:39