Search code examples
c++built-in-types

Cannot assign the value of INT_MIN to a long long


signed long long value = -2147483648;
    cout << ((signed long long)value);

outputs 2147483648 (no minus sign), why?


Solution

  • signed long long value = -2147483648;
    

    2147483648 cannot be represented in a 32-bit signed integer, so it is converted to an unsigned, then unary minus is applied (which doesn't change anything), and then it is assigned to the signed long long. Use -2147483648LL