Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize an unsigned long long type?

Tags:

c++

c

types

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.

like image 380
Sujay Avatar asked Apr 08 '10 06:04

Sujay


People also ask

How do you initialize long long int?

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.

How do you define unsigned long long?

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 .

How do you use unsigned long long int?

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.


2 Answers

Try suffixing your literal value with ULL

like image 65
codaddict Avatar answered Sep 30 '22 19:09

codaddict


First, be sure your compiler supports the long long type. Second, add a "ULL" suffix to the number.

like image 21
Jerry Coffin Avatar answered Sep 30 '22 18:09

Jerry Coffin