Take this line of code for example:
for(int i=n-1; ~i; --i)
My question is what does the ~i mean. What I already know is the for loops needs the following:
for (type var = ; condition; something to do with var) {
code here
}
But how is ~i a condition?
All I know is ~i returns the bitwise complement of i, or flip the bits.
falseand all non-zero values converted totrue.forloop continues iterating. If you think about what valueimust have so that~iis 0, you will have your answer.