+ 3

Can I extend already defined array?

let's say I need more then 5 users.

15th Jun 2016, 6:53 AM
Boris Atanasov
Boris Atanasov - avatar
10 Respostas
+ 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...
25th Jan 2017, 4:21 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
if by extend you mean change the size then the answer is no. You should use vectors to do that.
15th Jun 2016, 7:00 AM
Sardor
Sardor - avatar
+ 1
u can't. u can create new array and copy the data or you'd use std::vector
15th Jun 2016, 10:24 AM
VISHAL PRAJAPATI
VISHAL PRAJAPATI - avatar
+ 1
no u cant do it!. as the array is defined once u cant extend it
17th Jun 2016, 6:15 AM
Sai Krishna
Sai Krishna - avatar
+ 1
No you can't extend the already defined array
17th Jun 2016, 6:22 AM
Vipul Singh
Vipul Singh - avatar
0
nope, if yes then i even i wanna know..
15th Jun 2016, 7:51 AM
Nikhil Mishra
Nikhil Mishra - avatar
0
no, you can assign new value to that array but u can't extend the size of the array.
17th Jun 2016, 8:37 PM
Joydeep Roy
Joydeep Roy - avatar
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
17th Jun 2016, 9:42 PM
destro
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").
23rd Jun 2016, 6:55 AM
Nikola Dedović
0
No, you can not add more elements than the initially defined size of the array
25th Jan 2017, 4:31 PM
Ojala McOpiyo
Ojala McOpiyo - avatar