7. for文と一緒に使う
int A[100] = {48, 1, 2, 3, 22, 31};
for(int i = 1; i < 4; i++){
cout <<A[i] << endl;
}
出力
1
2
3
8. 配列の良いところ
int main(){
int a = 5;
int b = 10;
int c = 15;
int d = 20;
cout << a << endl;
cout << b << endl;
cout << c << endl;
cout << d << endl;
}
int main(){
int a[4] = {5, 10, 15, 20};
int i;
for( i=0 ; i<4 ; i++ ){
cout << a[i] << endl;
}
}
添字の数を変えるだけで別の数を操作
できるのでプログラムが短くなる!!
9. string
stringは文字列を入れる型
実は配列
string s;
s = "Ritsumeikan";
s[0] s[1] s[2] s[3] s[4] s[5] s[6] s[7] s[8] s[9] s[10]
R i t s u m e i k a n
実はs[11]には「文字列
がここで終わりです
よ!」というのを示す
NULL文字('¥0')が入って
います