Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The meaning of the symbol ~ on an array when that array is not a class

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Bitwise Operators

Bitwise Complement Operator

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading