Arrays

3 minutes
Share the link to this page
Copied
  Completed
An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed.

Transcript

Hello, and welcome to the 37th tutorial, the c++ programming series. And in this part we'll be looking at arrays. Arrays are a series of values with the same data type placed in memory next to each other, and they can be individually accessed using an index. So let's just show you how this works in c++, relatively many of other languages as well. So to create an array race in the how to how you will create a variable, so you've got your data type, so by the end, you put the name of your right when I any square brackets, you put how many elements you want your array 205 to keep it nice and simple. And this declared an array called array of five integers we can alternatively do is do equals and then you can assign the initial value.

So we're going to do 20 and then to put a different value separated with a comma or define 23 five triple seven Sorry about that. That was just my phone. And then to run this, this still works a okay. And what we're going to do, you can also just omit the actual number of elements, if you specify the effort value initially called by their, by that compile, go 12345 to five elements, so it's gonna be an array of size five, we're gonna put five anyway, because it just, we prefer it. And the reason we prefer is because we know we can look at it and think we have any elements when we initialize it great, but if we don't, we know the exact so but again, it's just totally up to you. And to access an element in that array was going to seek out the fourth element.

The low key here, that's just due to the line. When you I think to access the fall, fourth element, you do something and then you access number four in default. You don't if you've done any sort of computer science or any computer before, you'll know that instead of starting up one by 12345, etc, you start at zero, so it's both 01234, etc. So if you want to access the fourth element, you would do it square brackets not before but free, because this is an index zero, index one, index two, and index free aka the fourth element. So if we run that it will print out five, instead of printing out 23 it my thinking it's 123 and four, and to modify it is the same as also free does do AI. Three, we just assigned the voting for five six.

Now if we just simply copy and paste this, so we can print it out, run it, and it prints out 456 after we have assigned the value 4562 element three in the array of integers called I. That's it for this tutorial. Arrays are really easy to use, but they are immense. powerful and you will probably use these a lot. In the next part we're gonna be looking at multi dimensional arrays. If you have any questions feel free to message us at support at solar systems Dakota UK email will be in the description you can comment on this video or just directly message via YouTube.

Wherever you feel comfortable with is a Okay, all the required links or source code will also be in the description and as usual, thanks for watching and I hope you have a nice day.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.