+ 13

Can we create array whose size is unknown???

How do we take input of array whose size is not known?

19th Jun 2020, 1:21 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
5 odpowiedzi
+ 6
You can't. That's why arrays are known as static data structures, that means you have to assign the size at the compile time only. It is a general practice to take the array size large enough so that it can fullfill expected requirements. Or If you know the concept of dynamic memory allocation then there is a thing known as dynamic array. More famously known as *vectors*(defined in stl) in C++.
19th Jun 2020, 1:26 PM
Arsenic
Arsenic - avatar
+ 6
Thnks
19th Jun 2020, 3:14 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 5
for that you can Use Vectors
19th Jun 2020, 1:24 PM
Pratik Zinjurde
Pratik Zinjurde - avatar
+ 2
Use a vector (See http://www.cplusplus.com/reference/vector/vector/) or list (http://www.cplusplus.com/reference/list/list/ ). Vectors are better for indexing, and lists are better for inserting/removing.
21st Jun 2020, 2:15 AM
SapphireBlue
SapphireBlue - avatar
0
Hi! Previously I created a sample program that addresses this case. https://www.sololearn.com/Discuss/2372341/?ref=app
19th Jul 2020, 7:13 PM
Vasile Eftodii
Vasile Eftodii - avatar