+ 2

Tell advantages of array

9th Feb 2017, 7:02 PM
Yashasvi Rastogi
Yashasvi Rastogi - avatar
4 Respostas
+ 5
Imagine you hadn't: you should name every single variable you needed. For example: if you wanted to compute the average of, say, 20 numbers, you should name the variables like a, b, c, ... or a1, a2, a3... I'm sure you get the point. Plus, you couldn't add them up in a decent way. Compare sum = a1+a2+a3+... versus sum=0 for i in range(0,20): sum+=a[i] (ok, it's Python, but it works quite alike in C++ or Java). What if there was another variable, depending on the user's input? How could you name it, if you don't know if it's needed? With arrays, you simply append it.
9th Feb 2017, 7:54 PM
Álvaro
+ 2
one variable, more than one values. and the values of array it iteratable.
9th Feb 2017, 7:27 PM
K.C. Leung
K.C. Leung - avatar
+ 1
versus what? list? linked list? dictionary? tree?..
9th Feb 2017, 7:11 PM
Zilvinas Steckevicius
Zilvinas Steckevicius - avatar
+ 1
Answer is:- * Easy to specify * Free from run time overheads * Simple code * Fast sequential access
10th Feb 2017, 7:49 PM
Yashasvi Rastogi
Yashasvi Rastogi - avatar