In C++ or C, when you allocate memory using malloc or new you are asking for chunk of memory. But Compiler will always assign memory in pages. Now each page contains how many bytes of memory is configurable and system dependant. Whenever you are accessing the memory beyond your assign i.e. one page Segmentation fault will occur.
But always keep in mind for each memroy allocation, compiler never allocates one page for each allocation.
1) malloc for 100 bytes then compiler will assign one page (Consider page of 4KB)
2) malloc for 200 bytes then compiler will not asign any page for you but provide addres within same page. This is how memory is allocated by compiler.
Now if you access memory beyond your page you will get segmentation fault.
Last Wiki Answer Submitted: June 6, 2008 6:42 pm by 1234567898820 pts.