Each student is identified by 4 digit Id. The number of student is unknown. However the last id number is 0000. Which is the file. How do i intialize my array to what size?? Or do i have to wirte any loop. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Each student is identified by 4 digit Id. The number of student is unknown. However the last id number is 0000. Which is the file. How do i intialize my array to what size?? Or do i have to wirte any loop.

23rd Oct 2016, 1:48 AM
Kris prototype
Kris prototype - avatar
2 Answers
+ 2
int nStudents; cout << "Enter the number of students: "; cin >> nStudents; int *pStudents = new int[nStudents]; then you can use this pointer like you would a normal array. for (int i = 0; i < nStudents; i++) { cout << "Enter student id: "; cin >> pStudent[i]; }
23rd Oct 2016, 4:15 PM
Zeke Williams
Zeke Williams - avatar
0
int arr[]; //you can use empty brackets if you dont'n know the number of students...
23rd Oct 2016, 10:21 AM
Shah Zaib
Shah Zaib - avatar