Are there any library that dynamically allocates memory for integers in c++ ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Are there any library that dynamically allocates memory for integers in c++ ?

I want integer types in c++ function like it's in Python. There is no limit. The size and range of ints are dynamic in Python. How can I achieve this in cpp.

8th Mar 2020, 2:23 PM
Terminal_Phantom
Terminal_Phantom - avatar
7 Answers
+ 4
Yes, Ipang you guessed right
9th Mar 2020, 9:46 AM
Terminal_Phantom
Terminal_Phantom - avatar
+ 4
I don't believe this is possible in C++ which is a statically typed language where when you declare an integer variable, a fixed number of bytes is allocated, depending on the architecture.
10th Mar 2020, 4:27 AM
Sonic
Sonic - avatar
+ 3
I don't want an array of ints. I want an dynamic int type. With dynamic size and width.
9th Mar 2020, 9:47 AM
Terminal_Phantom
Terminal_Phantom - avatar
+ 3
Terminal_Phantom Bro, as I understand it, it was meant that way in the language. It was designed with small systems considerations. Bigger integers means more memory for each instance, I guess that wasn't the plan. But maybe others can suggest you some ways into it, by means of library or something else. I'm sticking around to learn ...
9th Mar 2020, 9:51 AM
Ipang
+ 3
Here is a specific problem. How can I store an int of size 32 bytes in cpp or more bytes as per my requirements ?
9th Mar 2020, 9:57 AM
Terminal_Phantom
Terminal_Phantom - avatar
+ 2
Terminal_Phantom Are you referring to the size and/or range width of the `int` type? as if whether C++ `int` can behave like Python `int`?
8th Mar 2020, 3:24 PM
Ipang
+ 1
Can we make library to achieve that in C
11th Jun 2021, 7:26 AM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar