Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4
No, stack overflow and segmentation fault are not the same. stack overflow comes under segmentation fault. segmentation faults are - 1. Writing to read-only memory 2. Null pointer dereference 3. Buffer overflow 4. Stack overflow you can also refer this - https://en.wikipedia.org/wiki/Segmentation_fault
22nd Feb 2022, 11:32 AM
Shaurya Kushwaha
+ 4
Both are different. Segmentation fault in simple terms is something that occurs when you try to access any memory address that is out of your assignment limits. For example if you have an array of 10 elements and you are trying to assign value to its 11th element. int arr[10]; arr[10] = 11; Another reason could be is while trying to access a pointer that has already been dereferenced. There could be other reasons as well.
22nd Feb 2022, 11:51 AM
Avinesh
Avinesh - avatar
+ 3
I think other explained it well but I would like to add a point that stack overflow doesn't always lead to segmentation fault. As Avinesh said, segfault simply occurs when your operating system detects a process trying to access restricted memory. Stack overflow on the other hands happens when your stack pointer tries to go beyond the memory allocated to *that perticular stack*, in a lucky case, it would try to access a restricted memory location which would cause your OS to throw a segfault, or in a worse case, that pointer may still point to a valid memory position ( belonging to the process ) and potentially altering/corrupting data there, which needless to say is not what one would want.
22nd Feb 2022, 2:12 PM
Arsenic
Arsenic - avatar