1
    int8_t a = -123;
    uint32_t b = 0;
    bool c= a < b;

Here 'c' is false as -123 gets converted to uint32

   int8_t a = -123;
   uint16_t b = 0;
   bool c= a < b;

'c' here is coming as true, why?

uint is given precedence in the operation as if any one of the operand is of type uint, the another one is also implicitly converted into uint type. Hence in the first scenario, the output is false, but why this is not followed in the second scenario.

Deepti
  • 11
  • 2
  • 4
    This is caused by promotion. In the first 1st case, both values are promoted to `uint32_t`. In the 2nd case, both values are promoted to `int`. Please, google for "C++ promotion" or see e.g. [SO: How do promotion rules work when the signedness on either side of a binary operator differ?](https://stackoverflow.com/a/6770275/7478597). – Scheff's Cat Aug 16 '17 at 05:15
  • Output of assembler and checking the code would be a second option although this might be a bit tedious... – Scheff's Cat Aug 16 '17 at 05:17

0 Answers0