Bitwise ‘&’ operator

5 is 101.

4 is 100.

5 & 4 is not 0:

101 
100 &
↓↓↓
100

Problem solved ✓


Clarification:

In C, every non-zero value satisfies the if condition. Meaning, if you write:

if (-5) {
  if (100) {
     // reachable code
  }
}

Whereas:

if (0) {
  destroyTheWorld(); // we are safe
}

Leave a Comment