Hello everyone I was going through a few programming questions and encounter one strange thing, The problem asked me to do some logic which is not relevant or nor I am asking the logic here, But the question involved the integers and said that I should keep in consideration that integer value be less than 10000000000 My doubt what data type to be used to store such ranges or, Lets just assume that some C program is used in some banking application which involves huge no of these magnitude, How do we store such huge no, Note: Even type 'long long' wont be able to store such huge no , Then how do we store such no ?
Asked
Active
Viewed 380 times
-2
-
9A `long long` can certainly store the value 10000000000. – Sneftel Mar 09 '15 at 07:56
-
1You could take the input as a string and then parse it accordingly. – Spikatrix Mar 09 '15 at 07:57
-
1@Sneftel What about the number greater than the range of long long ? – Rohit Saluja Mar 09 '15 at 07:57
-
1possible duplicate of [Are there any solid large integer implementations in C?](http://stackoverflow.com/questions/3191002/are-there-any-solid-large-integer-implementations-in-c) – Sneftel Mar 09 '15 at 07:58
-
2Don't use `long long`, you don't know how big it is in case the code needs to be portable. Use `int64_t`. – Lundin Mar 09 '15 at 07:58
-
@RohitSaluja then you'll need to use multiple primitives to store the number, as a bigint library does. – Sneftel Mar 09 '15 at 07:59
-
There are plenty of libraries that handle arithmetic to any precision, usually by storing the numbers as character strings or strings of BCD digits. – Mar 09 '15 at 07:59
-
1@Sneftel Except 10 billion will fit in a 64 bit integer without any big int libraries. – Lundin Mar 09 '15 at 08:00
-
@Lundin did you miss my first comment? – Sneftel Mar 09 '15 at 08:00
-
I think your question is being discussed here: http://stackoverflow.com/questions/23445662/how-to-store-a-integer-value-equal-to-1018-in-c-programs-or-c – A.R.K.S Mar 09 '15 at 08:03
-
@Lundin but for integer values less than 10000000000 then long long will always fit because it must be larger than or equal to 64 bits – phuclv Mar 09 '15 at 08:10
-
if you just want to work with "integer value be less than 10000000000" like the problem requires then definitely long long is the solution as that limit is not "huge" at all. If you need even larger numbers then it's unrelated to the problem you have, and there are already tons of duplicates on SO like [this](http://stackoverflow.com/questions/565150/bigint-in-c) and [this](http://stackoverflow.com/questions/5544293/how-to-work-on-big-integers-that-dont-fit-into-any-of-languages-data-structure?rq=1) – phuclv Mar 09 '15 at 08:38
-
You can find lots of solutions with these tags [tag:arbitrary-precision] and [tag:bigint] – phuclv Mar 09 '15 at 08:45
-
What is the base for `10000000000`? 16 (base ten)? 42? – greybeard Mar 09 '15 at 08:53
2 Answers
0
You could imagine the value stored in a database where numeric precision can be specified for data columns. But it's more likely that the particular value is specified to force you to think about how the algorithm or code would handle numeric overflow.
BTW, many systems use a 64 bit long long, which could hold the value you mention. Here's a great site to experiment with numbers and gain an intuitive feel for this:

Mark Harrison
- 297,451
- 125
- 333
- 465
0
if possible use int64_t
instead of long long
that is defined in standard library header stdint.h
. That holds 64 bit integers for sure. Larges number that can be represented is 2**63-1 and that is 9223372036854775807 (9e18). So it can hold 10000000000.

Luka Rahne
- 10,336
- 3
- 34
- 56
-
2long long must have at least 64 bits, so it can hold 10000000000 too, regardless of the real precision – phuclv Mar 09 '15 at 08:46