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?
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.
Without beating around the bush I would like to say that sometimes not in actual coding practice bt yes defintly in some competitions one might need very big data types bt I think we can do this. Why not take the entire sequence in the form of string and then use the atoi function to get the integer value it is I think politcally correct :: :)
#include<stdio.h>
#include<stdlib.h>
int main ()
{
int i;
char bigString [256];
printf ("Enter a number: ");
fgets (bigString, 256, stdin);
i = atoi (bigString);
printf ("The value entered is %d.",i);
return 0;
}
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.
The data type with the longest printed string is a signed data type, unless you have an integer type that has a maximum unsigned value that is one digit longer than the maximum signed value.
For example, a 4-bit integer unsigned would be at most two characters unsigned or one character plus the negative sign when signed.
So, you should pick a signed data type to represent the largest printed string. Which should be long long.
来源:https://stackoverflow.com/questions/8797092/what-is-the-largest-data-type-for-storing-and-printing-an-integer