*ptr = *ptr + 1; and *ptr = *ptr++; are different in the since that the first dereferences the location pointed to by ptr adds 1 to the value in there and stores the result back in that location. the second dereferences the location pointed to by ptr, stores the value in there in the same location (which is actually kinda pointless but that's not the ...


x++ - Post-increment operator ++x - Pre-increment operator In short, x++ - x is incremented after the current statement is evaluated. ++x - x is incremented before the current statement is evaluated. Huh? Well, lets say we have a function called foo which has a local variable x: int foo() { int x = 0; return x++; } In this function, x is ...


The problem turned out to be a memory allocation issue. I had declared another variable with too small an array size right before I declared my counter variable, so the first variable started running over into the second variable. Increasing the size of the first variable fixed the problem.


Just in case there's unclarity about the increment operator(s). In C, the increment operators actually increment the value without the need to assign it to anything. The original value is incremented even though the old value (or the new one, in case of the prefix increment operator, ++i) is returned. So if we have int i = 0; i++; // evaluates to 0, ...


Sounds like you are declaring the counter as int counter = 0; each time around the loop. If that's the case, make sure you only declare it once, outside the loop!

Only top voted, non community-wiki answers of a minimum length are eligible