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.

http://imgur.com/LpuaE72

here is the imagur link to my code and output. i have circled the problem.
The problem is i/j<=MAX // Note: <= is wrong . It will go out of bounds.

It needs to be i/j<MAX // Note: < is correct
Last edited on
Thanks a lot. that worked. but how did it not give me an error and affect another variable like this?
It is not defined what happens when a value is stored outside the array.

In your case p is affected. It depends on its physical memory address whether there is an affect or not.

The compiler cannot check a variable (i/j) that changes at runtime. Normally a C++ compiler doesn't do a bounds check at all.
Topic archived. No new replies allowed.