- In this video, I am introducing
a new concept called "array."
It is a unique concept to computer programing.
All programing languages use it.
However, there are slight differences in implementation.
Let's see how C is making use of an array,
and we'll start with defining what it is.
It is simply a collection of elements.
For example, 20 numbers, 50 letters,
60 records, financial data.
As long as the data are of the same type,
they can be stored in an array.
Actually, an array it's a series of memory locations,
each one labelled in a particular way,
and all grouped under the name of the array.
as we will see shortly.
When do we use arrays?
Whenever we need to store a temporary list.
"Temporary" reflects the fact that the list disappears
once the program ends.
For example, while you are playing a game,
you may need to store multiple data points
related to levels of a game,
data generated by functions for plotting later.
You could have any kind of numeric information
that needs to be sorted.
If we place it in a list, we can write a program
and that will traverse the list and sort the data.
Vectors in linear algebra that have multiple dimensions
or in physics.
We don't know in advance how many numbers
we are going to have,
so can cannot define variables X,Y,Z and so on
because we just don't know how many.
We will see how arrays allow us
to declare lists of data points
without knowing exactly how many of them
we are going to need.
Finally, matrices of data.
If you have any kind of experience with algebra,
you have learned about matrices, determinants,
and any other types of data that requires numerical tables
for processing in variable mathematical exercises,
problems, and so on.
Let's switch to code, and see how do we declare an array.
Very simple.
Line 16, 17 and 18 show a few examples of arrays.
The one on line 17 should already be familiar to you
because we actually used it in some instances
when we referred to a string as an array of characters.
Now we can see a bigger picture where an array can be
an int or a double, or any other data type available in C.
Line 16 shows an array of, for example,
20 slots in which you can store integer numbers.
Line 18, you can only store double precision numbers,
and up to 50 of them.
Another way to visualize an array is a hotel where,
at the floor of the hotel, there are multiple rooms.
They're all of the same type, in the sense that
they are all rooms.
And we can refer to room number one, room number two,
room number three, and so on.
In each one of those rooms, we can store any type of data.
We will see how this works in the upcoming videos.