I'm trying to initialize an unsigned long long int
type. But the compiler is throwing an error
"error: integer constant is too large for "long" type ".
The initialization is shown below :
unsigned long long temp = 1298307964911120440;
Can anybody please let me know what the problem is and suggest a solution for the same.
long long int num = 1000000*1000000; assuming you have 32-bit int s, the constant 1000000 is of type int , and the result of multiplying two int values is also of type int . In this case, the multiplication will overflow.
An unsigned version of the long long data type. An unsigned long long occupies 8 bytes of memory; it stores an integer from 0 to 2^64-1, which is approximately 1.8×10^19 (18 quintillion, or 18 billion billion). A synonym for the unsigned long long type is uint64 .
The maximum value that can be stored in unsigned long long int is stored as a constant in <climits> header file whose value can be used as ULLONG_MAX. The minimum value that can be stored in unsigned long long int is zero. In case of overflow or underflow of data type, the value is wrapped around.
Try suffixing your literal value with ULL
First, be sure your compiler supports the long long type. Second, add a "ULL" suffix to the number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With