Can you declare an array with no size? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can you declare an array with no size?

i have an idea on how to implement an array in my hailstone program, but I would like to declare it first as a function prototype before giving it a size. The size will be based on how many times the hailstone sequence runs. Any help would be much appreciated. v/r Sherwin Slaughter

24th Jan 2017, 9:41 PM
Progress101
Progress101 - avatar
4 Answers
+ 2
In C++ include <vector> or <list>. It allow you to create dynamic, resizable "array". Details are availible on C++ references. If you know exact size of array in some moment you'll can simply declare: int *array = new int[size]; When array won't be needed anymore you can clear memory: delete [] array;
24th Jan 2017, 10:49 PM
Adam Emieljaniuk
Adam Emieljaniuk - avatar
+ 1
var[] Array_name; That should do the trick
24th Jan 2017, 9:48 PM
Aaron
Aaron - avatar
0
@Aaron, Thank you.
24th Jan 2017, 11:48 PM
Progress101
Progress101 - avatar
0
@Adam Emieljaniuk, I'll look into the C++ references as well. Thank you.
24th Jan 2017, 11:49 PM
Progress101
Progress101 - avatar