Reputation: 292
Is it possible to use dynamic memory allocation, or some other method, to make a 1000-bit (or 1024-bit) integer variable?
Obviously, this is an insane amount, but I'm just using this amount as an example. Basically, can I make an integer any size I want? I'm thinking maybe dynamic memory allocation would work, or perhaps something to do with char arrays?
Upvotes: 2
Views: 396
Reputation: 311228
Depends on what exactly you mean.
If you mean "a fully functional int
that the compiler knows how to handle and can be used with the built-in arithmetic operators", the answer would be no.
If you mean "allocate an arbitrary size of memory that I'll treat as a continuous integer and write my own custom mathematical functions for", the answer is most definitely yes, and there are in fact several libraries that do exactly that.
Upvotes: 3
Reputation: 117681
Yes. For example the GNU Multiple Precision Arithmetic Library (GMP) does this.
Upvotes: 2