cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Array Size
Array Size
Jan 29, 2009 at 9:10am UTC
harryp
(16)
Is there any way in which the size of array is assigned on the basis of user's choice?
I know only variables of type const can be used for declaring array of a particular size, but how do I do it when the size depends on value entered by user?
Jan 29, 2009 at 9:33am UTC
elpis
(32)
I suggest you could use vectors instead.
http://www.cplusplus.com/reference/stl/vector/
Jan 29, 2009 at 10:25am UTC
tukuniata
(39)
you cannot do it with array use vector instead
Jan 29, 2009 at 10:29am UTC
mordekai
(52)
You can also do it with new, but don't forget to use delete.
http://www.cplusplus.com/doc/tutorial/dynamic.html
Feb 1, 2009 at 8:54am UTC
harryp
(16)
Thanks
Feb 1, 2009 at 4:49pm UTC
corbin
(3)
You could also use malloc if you wanted, but elpis and mordekai posted much better solutions ;p.
Feb 3, 2009 at 7:38pm UTC
Zaita
(2770)
malloc is a C style of memory allocation. better to recommend the use of new/delete instead.
Again, A vector is a better method.
Topic archived. No new replies allowed.