Quote Originally Posted by cooper1200 View Post
just a theoretical question this time. Lets suppose i have an array with n elements . Obviously the elements can be indexed by 0 to n - 1. However the question is does pointing the index at element n cause a seg fault or trying to access the data stored there cause the seg fault.
Seg faults sre usually generated by the OS.

On most hardware the segfault occurs when you try to access a virtual memory address where the OS doesn't know how to map it to a physical address.

Most common is for addresses around 0 when a NULL pointer is deferenced, but you also do so by accessing a virtual memory address outside of those assigned to the stack, the heap or the program's code area (and many others type of memory that a process might allocate).

Virtual memory is given to your process in pages (maybe with a size of 4KB), so if you access outside an array by a little bit you wont usually cause a seg fault. Examples of this could be accessing an array with an index of -1 or that of the number of elements in the array - usually these result in unexpected memory corruption, not a segfault.