// Ex510.cc // Sec. 5.1 of lecture // Array #include #include main() { const int N=5; double x[N]= {9,7,6,5,7}; int i; // N=6; // N is read-only cout << endl << " Array x : " << endl;; x[0] = 1.0; x[1] = -2; x[2] = -x[1]; x[3] = x[1]+x[2]; x[4] = x[1]*x[2]; // Acces to x[5] is not permitted !! for (i = 0; i < 5; i++) { cout << "x[" << i << "] = " << x[i] << endl; } cout << endl << "Not permitted: x[5] = " << x[5] << endl; const int NN=5, MM=1; float y[NN-MM+1]; int M=5; // not correct !! float z[M]; // String variables // const int L=10; // error wrt. "Mathematik" const int L=11; // 10+1 char word[L]; char word2[] = "Mathematik"; // man 3 string // man strcpy strcpy(word,"Mathematik"); cout << endl << word << endl; cout << endl << word2 << endl; for (i = 0; i < L; i++) { cout << word[i] << " " ; } cout << endl << endl; }