what is the largest datatype in c in which I can store a large values like 10^17 etc? and also tell how to take user input,store,print them in this particular case.
-
4Use `unsigned long long int`. It can store up to `2^64 - 1`. – haccks Jun 20 '15 at 11:15
1 Answers
A particular implemention might optionally support implementation-defined extended integer types (N1570 6.2.5
Types):
4) There may also be implementation-defined extended signed integer types.38) The standard and extended signed integer types are collectively called signed integer types.39)
6) The unsigned integer types that correspond to the extended signed integer types are the extended unsigned integer types. The standard and extended unsigned integer types are collectively called unsigned integer types.40)
The motivitation is likely to allow 128-bit wide integers, but it seems to be no interest of it. It's more likely that particular implementation supports such integers via extension such as __int128
in gcc.
However, if your requirement is up to 1017, then you will be fine with the standard unsigned integer type such as unsigned long long int
. It guaranteed to be at least 64-bits wide, thus possible range is at least [0, 264-1], that is slightly more than 18 * 1018.
Note that long long
types were introduced in C99, but it's likely that even older C89 compiler supports them through extension. Check you compiler's documentation for any details.
Both printf()
and scanf()
expects prefix ll
in format specifier. For instance:
unsigned long long n = ULLONG_MAX;
printf("lld", n);

- 36,988
- 6
- 90
- 137
-
-
I just found this on stack overflow while i was searching for how to scanf an __int128. As your answer refers it, do you know how to scanf it? I am trying to store numbers 30 digits long – Sep 10 '16 at 16:05
-
@TestitemQlstudop: See [this](http://stackoverflow.com/a/11658831/586873) answer. Long story short: you need to handle it by itself, or just use [GMP](https://gmplib.org/) library, that provides convenience functions like `gmp_scanf`. – Grzegorz Szpetkowski Sep 11 '16 at 00:46