&= and ++ together coincide with X = (X + 1) % 1024; but can be faster computed by the processor.
1024-1 is 11 1111 1111 in binary, so for numbers where X < 1024 , bitwise AND will have no effect (since any bit and 1 = the same bit). Interesting things begin to happen only where X β₯ 1024, so consider a loop iteration where X starts at 1023.
X++;
In the context, then what happens, X increases from 0 to 1023, and then returns to 0. You can see that this happens with much smaller numbers in the next test program. To make it easier to see, I use 4 (different power 2) instead of 1024.
#include <iostream> int main () { unsigned int x = 0; for (int ii = 0; ii < 10; ++ii) { x++; x &= (4-1); std::cout << "loop iteration #" << ii << ": x=" << x << std::endl; } return 0; } /* expected output: loop iteration
source share