unusual problem - variable decrements itself

I’m completely confused about this error. My global variable which i only use once in the program and increment it is getting back at one point and i don’t know why. I know there has to some error from my part but I can’t seem to figure it out. Help will be really appreciated.


here is the imagur link to my code and output. i have circled the problem.

Solving prime generator problem.

The screenshot does not show the complete code.Could you post the code on ideone.com or give the link to your codechef solution. It is not possible to judge without looking at the full code.

1 Like

Ok. I found the error. i was running the for loop till max(inclusive). So i changed <=MAX to <MAX and it works. but it’s weird that it didn’t give me out of bounds error and executed like this.

the output on ideone seems to be fine… What compiler are you using locally?
Also, no need to make variables unsigned… they can be simple int…