Can someone tell me how can I create array of numbers dynamically, without any for loop?
e.g. I want to create array like:
[0] => 10
[1] => 20
[2] => 30
[3] => 40
..
[9] => 100
Dynamic arrays in C++ are declared using the new keyword. We use square brackets to specify the number of items to be stored in the dynamic array. Once done with the array, we can free up the memory using the delete operator. Use the delete operator with [] to free the memory of all array elements.
A simple dynamic array can be constructed by allocating an array of fixed-size, typically larger than the number of elements immediately required.
A dynamic array is a random access, variable-size list data structure that allows elements to be added or removed. It is supplied with standard libraries in many modern programming languages. Dynamic arrays overcome a limit of static arrays, which have a fixed capacity that needs to be specified at allocation.
Java arrays are of static size. You should use a List (whose most frequently used implementation is ArrayList ) instead, which can grow and shrink dynamically and safely.
You could use range()
. The third argument is the number to step between values when interpolating between the start and ending values.
$numbers = range(10, 100, 10);
Good answers before me, but the best, what match exactly your assignment is use range(start, end, step)
this way:
$numbers = range(10, 100, 10);
var_dump($numbers);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With