bitwise-operators

Bitwise operator in case statement


I do not understand the following c++ statement:

int c;
switch (c) {
  case 'a': ... ;
  case 'c' | 0x100: ... ;
  case 'c': ...;
}

What is the difference between case 'c' and case 'c' | 0x100? Isn't it the same and case 'c' is never reached?


Solution

  • No, those are two different numbers (case expects a single constant numeric value).

    'c' equals to 0x063

    'c'|0x100 equals to 0x163