Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the largest data type for storing (and printing) an integer?

In C on a 32-bit system, which data type will store (and can therefore print) the largest integer? Is it long long or unsigned long? Is there an unsigned long long? And which is the most precise and politically correct?

like image 994
camel-man Avatar asked Jan 10 '12 00:01

camel-man


People also ask

Which data type can store largest integer?

Longer integers: long The long data type stores integers like int , but gives a wider range of values at the cost of taking more memory. Long stores at least 32 bits, giving it a range of -2,147,483,648 to 2,147,483,647. Alternatively, use unsigned long for a range of 0 to 4,294,967,295.

Which data type has the largest size?

Memo is the data type that has the largest storage capacity. It provides storage for variable length and arbitrary format data. There are two variations to Memo datatype: CLOB and BLOB data types. CLOB( Character Large Object) are used for storing text.

What data type should be used to store integers?

The integer data type ( int ) is used to represent whole numbers that can be stored within 32-bits. The big integer data type ( bigint ) is used to represent whole numbers that are outside the range of the integer data type and can be stored within 64 bits.


2 Answers

Your question is a bit unclear, but intmax_t is the largest signed integer-valued type (and uintmax_t is the largest unsigned integer type). These are typedefs defined in <stdint.h>, but if you are printing them, you need <inttypes.h> instead, and the PRInMAX macros for various values of n.

like image 176
wnoise Avatar answered Sep 21 '22 11:09

wnoise


In ISO C99 long long is at least 64bit which is the largest standard integer data type. It also comes as unsigned long long. Apparently your compiler might provide larger types wich defined by intmax_t and uintmax_t.

However based on your comments you might be looking for a bigint library like GMP. It allows for arbitrary long integers (and floating point) limited in length only by your system resources.

like image 21
ChrisWue Avatar answered Sep 21 '22 11:09

ChrisWue