Is it possible to create an integer of any size with dynamic memory?

Viewed 105

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?

2 Answers

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.

Related