The size of first dimension (first index) is optional in array initialization. Explain | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The size of first dimension (first index) is optional in array initialization. Explain

The size of first dimension (first index) is optional in array initialization. Explain

23rd Feb 2017, 3:38 PM
Srikanth Srinivasan
Srikanth Srinivasan - avatar
1 Answer
+ 1
In declaring an array as array[] as opposed to array[10], the first option creates an array just big enough for initialization. The second, creates an array size = 10, regardless of what you initialize it to, even if it's empty. Hope that helps. If you need dynamic arrays, look into vectors.
23rd Feb 2017, 4:59 PM
Thomas Rudolph
Thomas Rudolph - avatar