I have a strange problem. Inside a loop after a certain number iterations value of a variable changes. Nowhere in the loop I try to change its value but it changes!
The program is very long. But let me put some portion of it. Here when n=933 and k=1533 cent[255] changes?! I have checked up to these n and k and saw that cent[255] is not changing until these n and k.
What I would do is set a breakpoint to trip when n=933 and k=1533, then ste through the code and watch cent[255] to see where it changes.
Some debuggers also allow you to set breakpoints that trip when certain variables have changed -- so you could set a breakpoint on cent[255] to find exactly where the offending line is.
I did it. I gave the memory address of the unexpectedly changing variable. It says that number of hit is zero, that is value is not changing according to it. I also monitored that variable and it is changing :(
I also noticed that when I initialized some pointers as NULL that variable changes its value in another time, say n= 892, k= 147.
So I initialized all pointers as NULL but hopeless, still changing its value.
Well one way or another, I would try to find out exactly which line is changing it, then that will help narrow down where the problem is. If that means you have to step through the code line by line in the debugger until you find the culprit, then that's what I'd do.
I don't know details of differences of them but it seems that if former declaration is used members of array may be "stolen" somehow because no memory allocated for it. Good, but why it is so although [size] is written at the end for the former declaration?