Arrays in Programming
An array is a collection of similar data stored in a memory location. What is a collection? A collection is a large number of items. It can be two or two thousand. In programming, we work with data everywhere. Data could be anything a name, a number, a boolean, etc. That's why we need data to be stored in our memory. But how we can do that? the answer is variable. We just name that data to save a particular memory location. Whenever we need the data we just called the name and the data is read from the memory. Let's see an example:
name = "John"
Here John is data and the data had been saved into the name variable. If we need to work with john, we don't declare it every time. We just need to call it through the variable declaration. Let's back to the concept of array, if we have 500 names, How we can store them? Like:
name1 = "john", name2 = "jonas", name3 = "rayan", .... name500 = "alexander"
It is possible? I don't think. If possible then not maintainable. That's why in every programming language comes a concept called Array. We store all the data into one single variable through the array. Like:
name = ["john", "jonas", "rayan", ... , "alexander"]
Now the question comes, how we can find specific data that we need, and how are they actually different from each other? Good question! to solve this problem we have a concept called an index. Index basically a number that starts with 0 and till its length minus one. We can access each data through an index if we want. name[0] is point to "john", name[1] point to "jonas" ... name[499] points to "alexander".