I’m reading a C ++ code, the code has a line like this:
for(;;)
{
if(~theArray[i] & anotherCondition)
{
DoSomeThing();
}
}
For some values i code goes back to the beginning of the loop, what exactly does this expression ~
on array, do?
Can anybody help?
>Solution :
~
operator indicates bitwise complement.
Bitwise complement operator is an unary operator (works on only one operand). It changes 1 to 0 and 0 to 1.
For example:
35 = 00100011 (In Binary)
complement of 35 is
~ 00100011 = 11011100 which is equal to 220 (In decimal)
Please check below resources to learn more about it