Could anyone explain me what is segmentation fault exactly? When I compile on Eclipse it works perfectly but on the submission page, online compiler, it gives segmentation fault. http://ideone.com/lqyPi
Segfault is generally the program trying to access memory that it can't (or shouldn't in the first place). Also generally, the program produces a core dump file, to show that the core was dumped (no redundancy intended). This file can be used to debug, and one can use valgrind if the code is in C to check for such access violations. I think you can do the same with gdb, but my memory does not reach that far off. As for C++, I don't know of any tool to help with such cases(google might help here), but as a hint, segfaults often are caused by bad usage of pointers.
Did you check my code? I think the problem is that, I checked many times but I didn't find any problem.
For problems like segfaults... you may use gdb. I ran through your code with the exact same input as in the ideone.com paste, but no segfaulting. I compiled the code using the code::blocks MinGW compiler, and no warnings. How did you get any segfaults in the first place?
@bmp Valgrind works with any language :-D
Also, on the ideone.com page, it shows no errors :-D I think it raised the SIGSEGV because of the funky way it accepts input from stdin. I guess there's nothing to really worry about.
I also compiled on Eclipse and couple online compilers but no error. When i submitted on interviewstreet.com , it says segmentation error.
Possible errors could occur after the first prompt for input: if the user does not enter a valid number then the code goes wild!
"Possible errors" agdgdgdgwngo reminds us that we should always check our program's inputs!
Join our real-time social learning platform and learn together with your friends!