Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 644
There is nothing we can do Avatar asked Apr 04 '11 09:04

There is nothing we can do


People also ask

Can long long int store 10 18?

www.geeksforgeeks.org/advanced-c-boost-library/amp/ There is a rule by which you can calculate how many digit a data type can store and the logic is 2^10 = 10^3 (nearly) i.e as long long int is an 64 bit integer, it can support 18 digit number because 2^64 = 10^18(nearly) by the above rule.

Can long long int store 10 9?

The answer is yes, but you don't need unsigned long long , unsigned long would be enough. A 32 bit number can represent over 4 * 10^9.

What is INT_MIN in C++?

INT_MIN specifies that an integer variable cannot store any value below this limit. Values of INT_MAX and INT_MIN may vary from compiler to compiler. Following are typical values in a compiler where integers are stored using 32 bits. Value of INT_MAX is +2147483647. Value of INT_MIN is -2147483648.


1 Answers

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

like image 111
Erik Avatar answered Sep 24 '22 22:09

Erik