+ 1
what if i need to store values that cannot be stored in long long.
Sometimes we need to store big values but data types doesn't support their size. How can i store big values which can't be fitted in a normal long long or something similar
6 ответов
+ 4
You could also store each digit in a byte array.
Might be easier than Strings.😛
(Also takes up less memory)
+ 2
You can't. Exactly...
C++ has a Heap that Memory Spaces are taken from to be used. If you declare a variable, a piece of memory is takem from The Heap and Added to The Stack.
If you use Dynamic Memory, you'll know more about this.
What I'm getting to, is that when you declare variables, the variable type is very important. If you declare your numbered value as a normal interger, it will have a minimum of two bytes assigned to it.
However, if you wanted a number that was longer than a long-long-number... you could do the below.
A workaround to limitations is to concatenate your number outputs. It seems strange and impractical, but how else are you going to represent the amount of atoms on Earth in numbers?
So declare your numbers as strings, save them elsewhere as an int if needed, then concat them when needed.
I can't explain the difficulties you'll have when you have conflicting arguments or when the order breaks, but have a try.
Another workaround, much easier than the above, store your single number value as a string, then use a "convert to number format" function to use it in calculations. Actually, I should have put this first...
Anyway, answer: No but yes.
Reason: Storage limitations; can be bypassed with tricks.
endl;
+ 2
@shobhit yes, but you'll have to do each operation by yourself
0
but then would i be able to operate on with that data.