Can I extend already defined array? | Sololearn: Learn to code for FREE!

+3

Can I extend already defined array?

let's say I need more then 5 users.

6/15/2016 6:53:43 AM

Boris Atanasov

10 Answers

New Answer

+5

Though you cant't, here is a way... Initialize the array with a very large size(type arr[5000];), and then ask for a size of the array(n). then use a loop to get the n elements. Now since n<5000, you can increase n to your choice later...(n++ or n+=m). And add elements accordingly.. This is a basic but certified way...

+1

if by extend you mean change the size then the answer is no. You should use vectors to do that.

+1

u can't. u can create new array and copy the data or you'd use std::vector

+1

no u cant do it!. as the array is defined once u cant extend it

+1

No you can't extend the already defined array

0

nope, if yes then i even i wanna know..

0

no, you can assign new value to that array but u can't extend the size of the array.

0

no, an array is just a pre determined set of memory put aside for the program during runtime. it's static, however c++ does have a way to dynamically (run time) create memory and that's under vectors in the standard library

0

No but you can extend a special kind of "array" which is builted into a STD, namely "vector". Used when you don't know how many elements you will have in prg (for example, when you don't now how many elements you will input into that array-like "construct").

0

No, you can not add more elements than the initially defined size of the array