Same code outputs right and wrong answer with different compilers
source link: http://codeforces.com/blog/entry/107972
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Hello! I have a funny problem. I was solving a problem in C language and submitted a code. It showed wrong answer in test 1 when compiled with gcc compiler. But when I compiled the same code with g++ compiler, it gave the right answer. The code was written in C. Can anyone please explain this??? I am giving the submission links. Thanks in advance.
Sorry, but didn't you try to think about it? Input: Question you should be got in head: is everything all right in your code? (there so many blogs already with same "different compilers give different results, is it bug?"; No it is never bug in compilers, it's always bug in code). You know input in which you've got trouble. Try to "debug" it with paper and pen (or with gcc sanitizers if you know how to use it), and you will find trouble in code (I think that if you find it yourself it would be more enjoyable, maybe I'm wrong:) If after debug you've got nothing, then I'd assume that you don't know some shit about C/C++. But still, try it yourself first:) |
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK