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, so now it's time to see the solution and what do we want to do is to write a function,
write a function that simply gets an array, that gets an array in some way that we are going to see
right now.
And also the size of the array.
OK, the size of the array and all these function has to do is to find the sum of all the elements in
this given array.
So we can say that finds the sum of all elements in the array.
So that basically what our function should do and let's say also that the function we said previously,
it should it should function, should return the sum.
OK, so it finds it and then it returns the sum.
So the instructions are pretty clear to us.
And now what we are going to do is to write the signature of our function.
So first of all, what we are going to do is we know that let's suppose that we want to work with the
array of integers.
So the sum of an array of integers is also going to be an integer.
So that's why the type of the function is going to be int.
And now we are going to write the function name.
Let's call it some of array and this function should get two arguments, OK?
The first one should specify how to work with the array and the second one is the size of the array.
So let's say that in the main in the main function, we created some, let's call it test array.
So into array or a rather, let's say of size three and IT values are one, three and 10 for this example.
OK, and we know that these arrays created inside the main block and the array is has three elements,
one three a.m. and ARRL simply represents the name of the array as well as it also specifies where is
the first address of the first element of this array?
Right.
So we know there is a sequence of three elements starting from some address.
For example, let's say the address is three thousand in.
What we want to do is to call these functions some of Array and Paysite, these initial address where
the array resides.
So if we want to send to pass and address, we know that here on the function side, there should be
some variable getting this address.
And what variable basically you may think of using to store an address, it's probably going to be of
a pointer type, right?
It's a pointer to end.
So we are going to send the address of the first of the first R element in this disarray.
And this address is going to be received here by a parameter in our function.
So we are going to call it and be a R r OK, so in Star Purulia, it will hold the address of the array
and also we are going to fast here the size because we are working in some remote function and we should
know the size of the array and how we created our signature.
And now let's just write the implementation of these functions.
So there you go.
And here we are going to write everything regarding these function.
So it receives the address, it receives the size.
And now what we want to do is defined the sum of all the elements.
So in this case, one, three and ten, it's a total of 14.
So, for example, what we are going to need is to create additional variable int I, and it will simply
allow us to iterate over all the elements in this area.
And also we need to create additional variable called sum that will sum up everything in this array.
So enti in some equals to zero.
And now we are going to write our for a loop.
So four equal to zero.
Right, because we start from index zero up to I as long as I is less than size I plus plus which is
what we are, that is what we are going to do on every iteration to increment I by one.
So inside of the for loop it's going to be very simple and we actually are going to use just one command.
And this command is going to be to add the previous sum, to added the value of the current value that
we are looking at.
So at every duration we are going to look at specific index.
For example, when I was to zero, we are going to inspect this element when I equals to one this element
and when I equals the two of these elements and so on.
So we are going to submit.
In our some variable, so some equals to our previous some the sum that we have so far, plus the error
and of the eye index.
OK, so very simple.
We could just use this like some equal to PRR an index saying, OK, just in some sort of abbreviation.
I am writing it like this so it will be more clear to you guys.
And basically, once you are done with your for a loop, you are going to have all the sum, the sum
of all the elements in your array.
And what you are going to do is to return to a return just the sum.
Right, because we return the sum of all the elements.
So pretty simple, guys.
You just use here the pointer, pointer, pointer to end.
That is called the error.
It holds the address of the first element inside of the original array.
The actual array that you've created in your main function.
And then you simply iterate over all of its elements.
So basically PRR just points to this area, points to this one, and then when the eye index increments,
you point to this one and then to that one and so on.
So also if we want to make sure that everything works, we can create additional variable inside of
the main function.
Let's call it result.
Result some, let's call it just resolved.
And each should hold the value.
The sum of it is return from these function.
So what we are going to do now is the right result equals OK equals.
And here we are going to specify the function name.
OK.
The function name is some of the way in here.
We are going to pass it to our arguments.
The first argument is the address of the first element, which can be denoted by here by HRR.
And also we can send here the signs which in our example is just three.
So I hope that's clear.
And just to make sure that everything works, let's say a half of the resolve some equals to percentage
D, you know, just to see that it gives us 14 in our example.
And here we are going to specify result and basically there you go.
Let's just build it and run it.
OK, so build in Iran and we have a problem here.
Oops, that's my bad.
I took notes from Python and by mistake I use comments from Python and not from C..
So now we are ready to build and run it and hopefully everything will go smoothly and you can see the
results equals to 14.
Awesome guys.
Great job.
I hope you see how you can use pointers here to pass erase from the main function to some other or other
totally separated function that will make some operations on this array and return some result based
on your needs.
So thank you guys for watching.
It was a good video.
I hope you find this information useful.
Practice on your own.
Keep 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.