// Ex650.cc // Sec. 6.5 of lecture // Dynamic array of type student // Input: a.out < input.650 #include main() { struct Student { long long int matrikel; int skz; char name[30], vorname[20]; }; int i, n; Student *gruppe, *pg; // pointer at Student cout << endl; cout << " How many Students : "; cin >> n; // input n gruppe = new Student[n]; // allocate memory for (i = 0; i < n; i++) { cout << endl << "Student nr. " << i << endl; cout << "Familenname : "; cin >> gruppe[i].name; cout << "Vorname : "; cin >> (gruppe+i)->vorname; cout << "Matrikelnummer : "; cin >> gruppe[i].matrikel; cout << "SKZ : "; cin >> gruppe[i].skz; } cout << endl; i = 3; if ( i < n) { cout << endl; cout << "Student nr. " << i << " : "; cout << gruppe[i].vorname << " " << gruppe[i].name << " , "; cout << gruppe[i].matrikel << " , " << gruppe[i].skz << endl; // Let us have a look on equivalent data acesses pg = gruppe+i; cout << endl << " Test" << endl; // Access on string cout << pg->vorname << " " << (*pg).vorname << endl; // Acess on first string character cout << pg->vorname[0] << " " << *pg->vorname << " " << *(*pg).vorname << " " << (*pg).vorname[0] << endl; // Acess on fourth string character cout << pg->vorname[3] << " " << *(pg->vorname+3) << " " << *((*pg).vorname+3) << " " << (*pg).vorname[3] << endl; } delete [] gruppe; // deallocate memory }