+ 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

19th Sep 2017, 4:11 PM
shobhit
shobhit - avatar
6 Réponses
+ 4
You could also store each digit in a byte array. Might be easier than Strings.😛 (Also takes up less memory)
19th Sep 2017, 4:29 PM
Rrestoring faith
Rrestoring faith - avatar
+ 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;
19th Sep 2017, 4:24 PM
ghostwalker13
ghostwalker13 - avatar
+ 2
@shobhit yes, but you'll have to do each operation by yourself
19th Sep 2017, 5:15 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
but then would i be able to operate on with that data.
19th Sep 2017, 4:30 PM
shobhit
shobhit - avatar