In this episode, we are going to study the dynamic array of C++, known as "vectors". A dynamic array is an array, a homogeneous collection, a set of elements of the same type. It is said to be dynamic because its size can vary during the execution of the program. For example the array of the ages of the students attending this course could evolve during the execution, as new students register for the course. Dynamic arrays in C++ are represented by the "vector" type. In order to use the "vector" type, we must indicate to the compiler that we want this type, and therefore include the corresponding library with the <i>#include <vector></i> directive at the beginning of the program. In order to use a dynamic array, you must of course declare a variable of this type, namely, a variable of type "vector". That is done as usual, by indicating the name of the variable preceded by the type and here the type is <i>vector</i>, with between signs like this (chevrons), between less than character and greater than character, the type of each array element. So for example, if I want to declare an array which will contain integers, what I am going to do is to declare a variable here, which of type <i>vector<int></i>, <i>int</i> being the type of each element of the array. Beforehand, don't forget, so that all this compiles, to include the "vector" library. As already mentioned, the type of the elements of an array can be any type available in C++. So what you put here between chevrons in the definition of the type is any valid type, including eventually another array, we'll come back to that later. When you declare a variable of type array, you also think, like for any other variable, about initializing it. Their exists in fact, since the new C++ 2011 standard, five ways of initializing a dynamic array. You can either initialize it as empty, or explicitly give the list of values that you want to use at the beginning, or give it a size with eventually an identical value for all elements that you put in this array at the beginning, or make a copy of an already existing array. Let's have a look, in turn, at these different ways of initializing an array. To initialize an empty array, it's very simple : there isn't anything in particular to do. You only have to declare a variable of this type, <i>vector<int></i>, if, for example, you want an array of integers, but without adding anything at the end of the declaration, without putting an explicit initialization. At that moment, the array will be an array initialized by the compiler as being an empty array without any element. Contrariwise, if you want to initially give it values, for example put the values 20, 35, 26, 38 and 22 already at the beginning in your array, the fact remains that it's a dynamic array, it will be able to evolve. But if you want these values at the beginning, you'll use the syntax which gives here an explicit list in the initialization. So between the two opening and closing curly braces, a list of values. Of course, the values you give in this list must be of the same type as the type you have specified for your array. We can also write, although it isn't tolerated by all the compilers yet, instead of having here an initialization syntax as we have always had for the other variables, have a syntax here which initializes with the character =. Third case of initialization, if I want to set a size at the beginning, at that moment the syntax will be the following : we are, here in parentheses, not going to set a list of elements, but set an integer, a size. So for example, if I want my dynamic array to have with five elements at the beginning, I'll declare a dynamic array of integers, called here "tab", and behind it here, I'll specify that it begins initially with five elements. Anticipating a bit with a syntax that will come later, you must pay attention to the fact that here it is indeed a dynamic array that initially contains five elements and that it has nothing to do with a static array that would always contain five elements and which we couldn't make the size vary. Here we are still talking about dynamic arrays and not at all about arrays whose size is fixed and which can't evolve, yet. So a dynamic array, you can give it a size. If we only give it a size, the array is initialized at the beginning with elements which are all null, with that size. But we can also initialize them with different elements of the same value. If for example I want to begin my array, which stays dynamic, with five elements which will all have the value 1. At that moment, I'll declare my array as a dynamic array of integers with five elements which all have the value 1. So here, this second element is an element with a value which has to be of the same type as the type of the dynamic array, the type of the elements of the dynamic array. So here I put a 1, of type integer, which causes the five elements that I initialized to have the same value, 1. Whereas the 5 here, can be nothing but an integer, since it's a size. Whatever the array's type is, it's always a size that I give. Finally, last way of initializing a dynamic array. We can also initialize a dynamic array by making a copy of an already existing array. So for example here I can declare an array called "tab2", which will be a copy of another array. So here we'll copy element by element the array "tab1" in "tab2" but we'll indeed have two arrays which, at the beginning, are in the same situation. "tab1" and "tab2" both have five elements that each have the value 1 at the beginning. But then each of these two arrays "tab1" "and "tab2" will evolve separately. And for example we'll be able to eventually modify elements in "tab2", and vary "tab2" as we wish, independently from "tab1". They are indeed two completely separated arrays. We here have a copy of "tab1" in "tab2". So to sum up, we have the five following ways of initializing a dynamic array : Either empty, we don't put anything, I insist on this, after the name of the variable in its declaration. The array will here be empty. Or initialize it with an initial sequence of values. To do this we use an opening curly brace, a closing curly brace in the initializaion parentheses. Or initialize it with a given number of null elements. At that moment, in parentheses, we'll just put an integer. Or initialize it with a given number of elements, so we'll give its size, but with a value different from 0. So here we'll provide a value which is of the same type as the type announced for every element. Or, finally, make a copy of an already existing array, and make a copy element by element. So there are the five ways of initalizing a dynamic array.