Hello All
Can anyone provide me a sample code, executing which generates a segmentation falut. need to understand how it works.

Thanks.

Recommended Answers

All 5 Replies

Get a pointer/array then start writing outside bounds.

Get to it.

thanks... i cud able to generate it now.. but i used some differerent way.

Hello All
Can anyone provide me a sample code, executing which generates a segmentation falut. need to understand how it works.

Thanks.

If you really want it:

for(int *p ;;) *p = 5;

Good luck with it :P

Edit::
But I really don't see how you'd understand it better, in programming, you just have to avoid this.
The only thing you really have to understand about this is that you never write some data to random memory.

int i = 0;
int j = 1/i;

If the OP had first used Google, then there even was no need to start this thread, because all his questions are already answered on Wikipedia:
http://en.wikipedia.org/wiki/Segmentation_fault

However, I want to congratulate the OP for wasting the time of everyone who replied in this thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.