private
The program will read the value of 1 from the file and add that to sum, which will become 1. The value of EOF will be false, because the code has not yet read past the end of file so the loop will execute a second time. This time the input to data will fail, and data will be unchanged. Sum will be changed to the value of 2.
#include <iostream> #include <fstream> using namespace std; int main() { ifstream inFile; int sum = 0; int data; inFile.open("input.dat"); while(not inFile.eof()) { inFile >> data; sum += data; } inFile.close(); cout << sum << endl; return 0; }
Insertion and deletion are performed by moving all the data past the insertion/deletion point through the end of the array.
The "current" pointer is an index into the array.
The head pointer points to the first element in the list.
The head pointer initially points to nullptr.
The list is maintained by making sure that the list is always terminated by the nullptr.