Discussion – Lesson 2 - Dynamic memory management in C++
BackComments
2 messages from 2 displayed.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
Comments
Hi Manoj,
the length of a dynamically allocated array doesn't need to be passed as a
constant value (e. g. value 10
or 15
), it can be
passed just as any normal integer variable (e. g. byte
,
short
, int
etc...), for example:
int len = 10;// the variable could be of any integer data type as long as the value fits in its range
int* array = new int[len];
This way you can create an array of any desired length you need it to be.
If you run into a situation where you need the array to be able to expand itself (e. g. when you're adding new items to a warehouse stock), there is a container called vector , but that's a little advanced topic.
If you have any other questions regarding this or similar topic, feel free to ask.
2 messages from 2 displayed.