0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

C++の拡張for文 名前あってる??

Last updated at Posted at 2020-06-18

注意事項

自分用メモ何でテキトーです。あしからず。

for文はfor(int i=0; i<MAX; i++) ~ みたいな感じで書くものやと思ってたけど、違う書き方があるらしい

サンプルコード

# include<bits/stdc++.h>
using namespace std;

int main(){
	int n=3, sum=0;
	int num[3] = {1, 2, 3};

	/*これが拡張for*/
	for(int i: num) sum+=i;
	cout << sum << endl;
	return 0;
}

まあ要するに、for(変数:配列)的な書き方で、配列の前要素にアクセスできる感じかな?

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?