Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
What is going on, guys?
My name is Vlad.
And now we are going to talk about how to declare and how to initialize arrays.
So when we talk about data types, we usually should start with the following question, how we should
declare it.
How should we declare an array?
This simply means how can we specify the creation of something new?
How can we create a new array so similar to working with variables of different types which you have
seen how that's being done in most of the previous chapters?
The first thing that we need to do before using them is to specify that these variables do exist, that
someone has created them for us or we created them.
Right.
So it's also the same for a race.
The first thing that we have to do to work with the race is to declare them.
Now, once you declare that you are ready to do different types of operations, including accessing
different elements of the array, assigning values to elements, input output and so on.
Okay.
So I hope that's clear.
And now let's take a look at the declaration see index in our C programming language.
So we said that for the simple variables we've talked about so far, we used to declare them like this
with, first of all, specify the type of the variable.
And then we specified the names of four.
In this example, we used int grade and we know that grade is the name of the variable and end is a
sexually it's type, the type of the variable integer.
So that's a simple variable symbol box with the name grade, which is simply used to hold your grade
when your last exam and it will be of an integer type.
Okay.
And another example may be like double salary.
Right.
Some variable to some simple variable to hold your salary and it's of a floating point type B double
type.
We also have if we want char, my char and other variable to store one character.
And we can specify a lot of other examples here for the declaration of different variables of different
names and of different types which specify how you create and basically how you declare a simple variable
is simple variable.
It's just my my analogy to to let you understand it in more with more ease on how to understand arrays.
Okay.
So we define different simple variables with different names and different types.
That's it.
And that's basically what we've learned so far.
And now we're ready to proceed and to talk about how the declaration of arrays looks like in our language.
So the first thing to bear in mind is the fact that we are creating some sort of collection of elements.
And this collection of elements is going to reside under one roof called an array.
So similarly to creating a great variable, we are just using INT.
We will create an array of grades that will hold a collection of grades and we do so like the following.
First of all, we specify the type end.
Then we use the name of this collection of this array.
And in the square brackets we specify its size.
Meaning how many variables.
Great.
How many grades we want to hold in these collection.
So the name of this array we've just created is grades.
This array has five elements.
We can see the size of the array in these square brackets and the type of each of the elements, the
type of every grade is an integer similar to what we've created, just singular, a simple variable.
Is that clear?
So far enough.
Complicated, right.
One roof.
And under these collection, under this roof, we have a collecting multiple elements.
We may have multiple grades.
So also, please note that all the five elements we've been visa array are, first of all, aren't initialized.
You created the end of the array, but you didn't initialize anything.
Just like with simple variables.
If we didn't initialize them, then they are going to be on initialized.
We didn't sign any value to them.
So once again, here in the square racket's, we have the size of the array here.
We can see the type of each of the elements within this collection with the inverse array.
And here we can see actually the elements inside of this array.
Okay, first of all, if we did not assign any value, then they are going to be on initialized.
So we just created our array.
And now we want to see what we can do next with it.
You will be able to read.
Data from the user.
For example, if the user will have five grades, we will be able to read these grades and store them
inside of each of these elements in the collection, in this array, or maybe will.
We will be able to assign different values based on our needs or to print the results and so on and
so forth.
So once again, quickly to summarize everything up, the necessary steps to declare an array are first
of all, you specify the type of the elements you would like the array to HALD, whether the type of
the elements should be an integer like we've used in the previous example, or even may be offering
a double type, B char type and so on.
Then you should specify the name of the array, some appropriate unique name which will allow us to
white densify this particular array over some other array.
Right.
Which has a different name.
We should be able to distinguish between different arrays.
So that's why we should have a unique name for each of them.
Makes sense, right.
And lastly, what we want to do is to specify the lengths of the array.
And this could be done by using the square brackets.
So the length of the array simply says how many elements of the specified type.
We've defined it.
Step one are going to be in this particular array.
Please note that the size of the array must be constant.
And it's very important that you define the size of your array as constant.
And that's important because if you don't do so, then the program is simply not going to work.
It's not going to compile.
And specifying the size of the array is constant, is done mainly.
So the computer will know at the compilation phase how much memory we'll need to allocate for the whole
array.
Since the arrays stored as a sequence of fellowman, just one element after the other.
That's actually how it's stored in the memory of the computer.
It's simply a sequence of elements.
So basically you've got the idea and we can say that these were the steps for declaring arrays.
And now let's create another array which will be used to hold salaries off employees in a company.
So now we've created an array of salaries.
And each element in this array is going to be off a floating coin type.
And the number of elements in this array is 10.
And basically, that's makes sense, right?
Because the type of the salary is probably not going to be of an integer type, but rather it would
be of a double type or free flow type.
So that's why we created an array of a floating point type of values.
And probably in a company there is more than just one employee.
So, for example, 10 employees.
And we therefore created an array of size 10.
And you can also define an array of characters by using char my array, let's say.
This way of a size four hundred.
Simple as that.
Just know that once you've decided on the type of the array, it will be the type of all the arrays
elements.
You can't let the first two to be of type end.
And the next three are to be of type double.
And the last five let's say, to be even of type char.
That's not possible.
Once you've decided on the type of the array, all the elements of the array will have the same particular
type.
So in the first example, we can see here with the salaries, all the elements within this array, within
this collection are going to be of a floating point of a double type.
And in the second example were where we created an array of characters of size of a one hundredth size.
All the elements are going to be of a character type.
So I hope that's clear.
Guys, I hope you understand now how to create an array, how to specify its size, its name and its
type.
And you are ready to move on the next video where we are going to talk about how to initialize an array.
So I'll see you there.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.