• C

Dynamic Arrays

Is there anyway in C or C++ to use initialise the size of an array at run time and also be able to change it? Thanks.
onka34Asked:
Who is Participating?
 
arunprakashConnect With a Mentor Commented:
try using the Standard template library.
it has classes called Deque, vector which can take care of this dynamic expanding and shrinking arrays

u can do
array.push_back(element)
element can be off any type
0
 
ozoCommented:
malloc/realloc
0
 
jjiCommented:
Don't forget 'free' & 'calloc'.
0
 
bsutrisCommented:
c cannot change array size but if you use pointer and you use it like an array, you can change the size of the pointer
0
 
onka34Author Commented:
Thanks :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.