-4

I did not find an array at stackoverflow and google, and it seems that everyone is avoiding this problem, and I want to know why there is an array? Or when the array appears to solve the problem?

yaningdou
  • 23
  • 5

2 Answers2

0

Consider a situation where we need to store five integer numbers. If we use programming's simple variable and data type concepts, then we need five variables of int data type and the program will be as follows

int  number1 = 10; 
int  number2 = 20; 
int  number3 = 30; 

for a list of large numbers, this is obviously tedious. So in order to solve this problem we can use something like this:

 int number[3] = {10, 20, 30};

As we can see here, we can do that on single line.

adkstar
  • 168
  • 8
-1

lest suppose that you are creating a software to a bakery and you need to store the qty of every cake type that they have per type and they have 500 types of cakes, are you going to create 500 variables? that's when the array is useful.

  • *are you going to create 500 variables* yes. An array of 500 is 500 variables held so that they relate to each other. So, yes, yes you are. – Liam Oct 03 '17 at 12:27
  • This community is mainly to help if you stuck during actual implementation. Please try it on your on and share sample code if you are stuck. – Vijayanath Viswanathan Oct 03 '17 at 12:34
  • Liam, Ik that you are creating 500 variables, but you are creating 500 variables in 1 easy to read line, plus in many languages an array has some functions already implemented to sort it, expand it and shrink it if necessary – Emmanuel Robles Oct 04 '17 at 14:06
  • Vijayanath Viswanatha, he just ask why an array is necessary, there is no need for a sample of code, i try to explain him the same way my professor explain me – Emmanuel Robles Oct 04 '17 at 14:12