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
All right, guys.
So know that you know how to declare an array and also you know how to initialize an array.
That's time that we learn how we can access each of its elements.
So, first of all, we need to understand that an array is just a collection of fail amounts.
We also said that these elements are organized in some manner.
How are they organized?
Simply in some consecutive manner?
Simply one after the other.
And we can refer and access any of these elements by using their, let's say, location within this
given array.
So we can say that every element, every element in an array has its location.
And this location is called an index.
And in C land, which we say that the first element is located at index zero.
OK.
So it index zero.
We have our first element.
And the second element will be, of course, located under index number one and so on and so forth.
You've got the idea.
OK.
So if you have an array with five elements total, then the last index will be.
Think about it for a second.
Okay.
WOR just take a look at the screen right now.
And you are right, the index of the last element.
The fifth element in this array will be four.
OK, so the first element will be at index zero.
And the last element will be at index size minus one.
The size of the array which in this example is five minus one, which is a total of four.
So that's how you find of that.
That's how you treat Aurora.
That's shown some guidelines that the first element is at index zero and the last element is an index
size minus one.
Please note that indexes should always been to jurors and also make sure that you do not exceed the
size of the array.
When you try to access one of its elements.
For example, if you have an array with five elements, then your last element in the array will be
at index four and not at index five.
So make sure you're not trying to access different addresses that do not belong to you.
Otherwise, if you don't pay attention to it, you may end up with an access violation error.
And that's simply because your program is not intended for working with the address you are trying to
access.
OK.
These value or data that is stored on their Index five does not belong to your program and that's why
you are going to get an access violation error.
Just like in real life.
Don't try to access what's not yours.
And because the compiler is not always going to warn you about your attempts to access things that do
not belong to you, these responsibilities on you, the developer.
So now we know that indexes specify the location of elements within the array.
So let's create a simple Interrail it's created and initialize it.
OK, so array initialization.
So how it looks like.
So first of all, you specify Ent., which simply tells what will be the type of all of the elements
inside of this array.
Then you use of the array name.
Square brackets to specify that it's an array.
And in the curly brackets you specify all the values that this array will have.
OK.
We didn't even specify the size of the array.
But it knows by itself well how to fill up this array.
So on the left side, you can see this syntax in our C programming language.
And on the right right side, you can see basically what happens behind the scenes.
OK, how of the array is stored in the memory?
And now if we want to talk about how you can access one of of the elements of the array or any of the
elements in this array, you can simply do these by specifying the index of the element that you want
to access.
In square brackets.
OK.
So you specify the array name.
First of all, you specify the array name.
And then you open square brackets and feeling the index of your desired element.
And then, of course, you close the square rockets.
So, for example, we can see here that we use the test the way we've initialized previously.
This is the name of the array.
And in the square brackets, we use the number two of the index two, which simply says go to test the
ray to location.
Number two or two index still.
And take the.
Value that is stored there.
Which in this case is just three.
So now once you know how to access you any value within a given array, you can access, change it,
modify however you like.
You can read from the user using scanner function and so on.
So how would you change the value of one of the elements?
Basically what you have to do is the first of all, access.
First of all, you access the element by using the array name and its index.
OK.
So let's say we want to access the last element and to change it to be nine.
So that's how you access it.
The last element.
And now you can use the assignment operation to assign a new value to it.
So, for example, we'll just use equals two nine.
And what it will do.
It will modify from 10 to just nine.
OK, so that's how you access and modify.
OK, that's an example of how we modify a value within a given array.
And also we can do pretty much the same if we want to print out some value of some element within visa
rate.
So, for example, we can print out the value of the first element of the array.
And we just access it just like we've done it previously.
So we specify the array name and the index we want to access.
And then we simply access its value.
So in this case, what will be printed is just to write, because two is the value off of the first
element in this array.
OK.
So now if we want to print out idea of the second value on this array.
The second element, we will use dest array and index number one, which will print simply five to the
screen.
Good, good, good guys.
And now you know how to access, modify and print the values of elements within a given array.
And now it's time to write a simple program that will create an array of, let's say, five grades,
get the grades as input from the user and find out what is the lowest grade in this given array.
Let's just go over the code here line by line.
So first of all, we include the standard input output library.
Then we start our main function.
And now what we're doing, if we is we declare are a an array of in the jurors.
And the name of this array is a grades and it's of size five.
And what we are also going to do is to create an AI variable that will help us using the duration of
the loop to read the valleys, the grades from the user at every time.
And also what we are going to do is to create another additional variable called lowest grade.
And it will store the lowest grade so far while we run our loop.
So let's create our for a loop because we know it should be done only five times.
So for I equals to zero as long as I is less than five.
Then on every iteration, we are going to increment I by one.
And in the loop, buddy, we are going to specify these following message after grade number.
And instead of these percentages, we we are just going to specify plus one.
So the first iteration will have enter grade number one and their array number two and so on and so
forth and on every duration we are going to read the value from the user.
The grade he inserts and storeyed inside are its corresponding position, its course corresponding location
inside of these grades array.
So we as the ampersand to specify the address where grades aren't the index.
I reside resides and we are going to put inside this location.
This element, the value that we've read from the user, from the console application.
So once we are done with our for a loop, we are basically going to add to initialize kind of far set
some value, some default value, which is a must step to the lowest grade.
So we will assume that the lowest the grade is our first grade that a user inserted.
And then what we are going to do is to create another or for a loop.
Okay.
That runs from I equals to one.
As long as is less than five.
And we are going to see if there is any lower grade inside of these array of grades.
And if that's the case, if we find that some element in this array is lower than the lowest grade so
far, we are just going to update the lowest.
Great to be equal to these particular grade because we are looking for the lowest grade inside of this
array of grades.
And once we are done with the second loop, we are going simply to print the lowest grade to the screen.
So we know that at this point, at this print off-line, we are over.
These two are for loops and we know that lowest grade that these variable will hold the lowest grade
in these grades array.
So if we take a look at how some some example.
OK.
So enter grade number one.
Let's say seventy eight.
Grade number and grade.
Number two, 60, 80.
And let's say 90 and a hundred.
OK.
So after inserting all these grades, we will have an array of five elements.
And the first element will be equal to 70.
The second one to 60, 80, 90 and a hundredth.
This will be our array of grades.
Now, the second iteration is going to run and to find out what is the lowest grade inside of this array
and a corresponding message with your lowest grade is 60 will be printed to the screen.
And we can see that it's exactly what we expected our program to find out, because visually we can
see.
Right, because it's a simple program that 60 is the lowest grade.
Now, once you've got all your grades and you've found out what is the lowest grade, you may also want
to print out all the grades to the screen just to take another look at them, for example.
OK.
So how will you do it?
How will you accomplish these tasks?
Can you simply use just one print off-line to print the whole array?
Something like this.
Print f your grades are percentage the and specified grades and we know that grades is in an array.
Come on, you can, you can go and try this one on your own to run this command and see what happens.
And basically what you're probably going to see is that not all the grades were printed out.
We have a total of five of these elements, but only one strange value was printed maybe on your screen.
It's some other value, but it's still very strange why some strange value was printed out.
If we have some grades and it's five elements.
So why is that?
So if we take a look at the following array, let's say that these are the grades the user specified.
We can clearly see that this number.
On the screen is actually not even a part of our ouray, okay?
It's not a value.
It does not represent any value.
So what is this number you see when we declare an array or anything else?
It will reside somewhere in the computer's memory and it should have some unique address where, for
example, it can be stored.
OK.
Some unique place.
So this way, the way we've just seen that we can print our grades, how we've done it are simple.
We simply printed out the address of the grades array.
And although it's nice that we can print the actual addressing memory of a given variable of a given
array.
That's not what we wanted.
That's another way to print all the arrays, elements or values.
So how should we do it?
So there is no magic in C programming language.
If you want to print all the elements of the array, you must go over each and every one of them.
And this can be done using loops.
All right.
So first of all, let's use a for loop to iterate over all the elements of this array from index zero
up to index for five is not included here.
Right.
And here we know that I will represent the index of each of the elements in these array as well as it
will also allow us to access any of them.
So if we want to access and print the values, we can use that print off-line.
OK, so print F grades at the index.
I equals to the value of this particular index.
So Van, on the first thing duration we are going to print grades at the index of zero equals to 70.
Then on the second iteration equals 60 to 100.
And then to 80.
And so on.
Until the last element which is 90.
OK.
So that's how you print all the elements of your given array.
And it doesn't matter if this array is just an integer array or characters array or floating point array.
The structure of printing all the elements of this array will be pretty much the same.
And also, if you would like to print the elements of the array starting from the last element up to
the first and not vice versa, what would you do?
So this this approach of just starting from the last index and then on discriminating one are from from
the index going to the left by the index is very straightforward.
In this case, we simply going to print all the elements starting from the last index to the first one.
And this index in our example is simply four.
So I hope that's clear to you guys.
And now for the end, let's talk about how all the elements of the array are arranged.
Basically, array is a consecutive sequence of elements.
The name of the array in our example is grades, and it actually represents the address of the first
element of that array.
Right after the first element of this array lies the second one in in sort of a consecutive manner.
So the addresses in memory of the elements of the array are simply organized one after another.
You can see that the address jumps by four.
Right.
And the reason for that is because we have an array of grades, an array of integers.
So we know that each element in this array is off an integer type.
And we know that an integer is just four bytes.
So do store an integer in terms of memory usage.
You need four bytes.
That's why the address of the second element is greater by four than the first.
That's the difference between every two AGC and two elements.
So I hope this video makes it clear to how you can initialize, declare you as read, modify axis and
so on.
Basically how you can do most of the operations using arrays.
So this is it for these video guys.
I think we've covered it up a lot in a very short time and probably we are very close to practicing.
So have a good day.
Keep on moving forward and I'll see you in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.