I am still new to C++. I am working on a program to read a set of list. I know a segmentation fault can be caused by accessing an array out of bound, but the compiler points out the fault happens at fin(stream) to read data into a double-type variable, and it still can read successfully when accessing the first part of the list.
Accessing an array out of bounds causes the program behavior to become undefined. Once behavior is undefined, the program can do anything, including:
* Crash immediately.
* Continue to run until termination without any errors or crashes.
* Continue to run until termination without crashing, but producing erroneous results.
* Crash at a later time in execution, at a code location arbitrarily far from the code that corrupted memory. Note that this implies that, in the case of memory corruption, the code location where the program crashed doesn't give any information about the code with the bug.
* Corrupt or delete important files.
* Make demons fly out your nose.
Line 29 looks wrong. If counter == 0, you'll write at index[i][num_ph[i]], which from what I can see it's one past the end of index[i].