230 views

2 Answers

1 votes
1 votes

there is so many ways for segmentation fault...

1) dereferencing null pointer

2) accessing some other process memory

3) uninitialized memory

4) accessing memory freed up by this process

5) attempts to access a memory location in a way that is not allowed (for example, attempting to write to a read-only location, or to overwrite part of the operating system). And many more...

u can refer all that points here https://www.google.co.in/url?q=https://en.m.wikipedia.org/wiki/Segmentation_fault&sa=U&ved=0ahUKEwituOzEwtPbAhVIP48KHZ-9CNcQFggTMAI&usg=AOvVaw1tO8fnqCluBjBkT2qUSfaH

 

let come to your question.... It accessing memory freed up by this process by the k[0] , therefore segmentation fault occurs..

0 votes
0 votes
The trick lies in the fact that when the control returns from the m function, all memories allocated to the variables during execution of m function are cleared. So, even though address of a is returned, this memory location no longer contains data of array a. So, there will be a segmentation fault.

No related questions found