In the previous episodes, we have mostly focused on dynamic arrays. Namely, arrays whose size can change during the course of the program. Let us now focus on arrays whose size is known a priori. A priori means, at the time when we are writing the program. Then, the size cannot vary during the usage. For example, if we are trying to code a program on two-dimensional geometry, with two-dimensional vectors, our arrays will always contain two coorddinates. This number is known a priori : it is 2, It does not vary during the course of the program. Another example: if you wish to program a chess game. A priori, before you start writing the program, you know, for example, that there will be two players. You know that this number will never change. You also know that the chessboard has 8 rows and 8 columns. You know these numbers a priori and they will not change. We are in the case where the size is known a priori and does not evolve. Thus, in this part here of the table. We call those "static arrays" or "fix-sized arrays". In C++, there are, since the new C++-11 norm, two types of fix-sized arrays. The "array" type introduced with this new norm in 2011, and the arrays inherited from C++'s ancester: the C language. We call those the arrays "à la C". In this episode, we will now focus on the C++-11 "arrays". The "arrays" have been introduced in the new C++-11 norm since the arrays "à la C", also called "building arrays" beget a few inconveniences. First of all, they are systematically passed by reference, even if we do not put the '&' sign of the passage by reference to the function arguments. The arrays "à la C" are passed by reference. Secondly, they are never aware of their own size. On the other hand, for C++-11 "arrays", just like "vectors", we have an easy way to know their size. Also, arrays "à la C" cannot be globally manipulated. If we have an array "tab1" and an array "tab2", we cannot do, with arrays "à la C", " tab1 = tab2 ". Also, we cannot have a function return an array "à la C", The return type of a function cannot be an "array à la C". Finally, "arrays à la C" have a particular initialization syntax which is not as general as, for example, the "vectors. Consequently, we daresay that, since the 2011 norm, since the new "arrays" type, the "arrays à la C" no longer have any use in C++. However, they used to be widely used, and therefore, by inertia, by habit, they will still be widely used. For the ones of you who would like to study this topic, we will add an annexe on the "arrays à la C". Let us now move on the "arrays" of C++-11. We want to use a fix-sized array, an array whose size is known when we are writing the program. This is the decisive question you need to ask yourself when hesitating between "array" and "vector". In order to declare a fix-sized array, we will use the "array" type. Of course, our program will need to start with the directive "#include<array> ". Then, we will declare our array with the keyword "array". Just after, we will write the type and the size, which is indeed known. This size is what is new compared to "vectors". Indeed, it is known when we are writing the program. Then, as usual, we will finish with the name we wish to give to the array. For example, if we wish to declare an array containing doubles. An array whose size is fixed 3, and containing doubles only, we will write : " array< double , 3> " and, just after, the name. For example, here "vecteur_3d ". Beforehand, we have included, at the beginning of our programm the "array" library. We this declaration, we thus have an "array", which is a fix-sized array. Its size will not be able to evolve. The size given at the very beginning will be the size during the whole run of the program. It contains enough room to store three doubles. Another example, if we wished to declare the inhabitants of a certain numbers of districts (known a priori). We can very well declare it like this, a constant expression. "const", the number of districts. It is of the "size_t" type since we know that we are indicating an array size here. Thus, "nb_cantons", the name of the variable. [TN: "canton" means "district"] Here, we can initialize it to 26. [TN: there are 26 districts in Switzerland]. This then allows us to make good use of this variable here, as the number of districts in our dynamic array here : An "array" of "unsigned int". Those are positive integers. The number of inhabitants is a positive integer. We are indicating the name here. Therefore, "habitant" is an array containing exactly 26 unsigned integers (26 unsigned int ). We have just seen how to declare a fix-sized array. Of course, we can also initialize it. This means we can give it values when we declare it. For that, we use a usual syntax, rather similar to the one encountered for the vectors. Between parentheses here, the value for an array, that is, all the values. Of course, we should not forget the braces for a set of values indicating the initial values of the aray; each value being separated by a comma. For example, if we wish to declare an array with 5 integers, a static array, a fix-sized array of 5 inzegers, we declare, here, "array". Each element will be of the int type. Then, we will pass the size which is known while we are writing the program. Here, we have previously declared it as a constant expression of the type "size_t". We decided to call it "taille" [TN: means "size"], and it contains 5. Thus, we will declare an array containing 5 integers. We call this array "ages". Then, we initialize it between parentheses with the values given as a set of values with the braces. The set of value is separated by commas. Thus, 20, 35, 26, 38, 22; which will give us the array represented here. There is a second way to initialize arrays. We had seen it already for the dynamic arrays. It is the equals sign. Then, again, on the other side of the equals sign, the set of values between braces and separated by commas. In the previous example, we could have used this way. Of course, we cannot use both ways at the same time. It is an alternative. But, we could have declared our "ages" array and initialized it with the equals sign and braces. By the way, certain compilers will only tolerate this second initialization way. Others tolerate both ways. Also, please note that an uninitialized fix-sized array may contain just about anything. This means we do not know what it contains. Now that we have declared and initialized our fix-sized array, we may start using it. There is here nothing more in comparison with "vectors". The syntax is truly the same. If we want to use an element at the position "i" of a static array called "tab", we will use " tab[i] ". This is exactly the same as for vectors. We can also iterate on a static array with an exact similar syntax as the one used for vectors. We can either use the C++-11 "for" : for(auto element : tableau) or with a classical "for". The "array"s have also a specific function "size" returning their size. Again, we can very well write, as we did for dynamic arrays, " tab.size() " to obtain the size of a static array "tab". We can also use global assignments. Globally assign an array "tab1" to another "tab2". If we have declared an array of integers "tab1" which size is 3 - its size will not change - initialized to the values 1, 2 and 3. We can very well copy it directly into another static array of the same size (3, here) by writing this : " tab2 = tab1 ". This will fully copy "tab1" into "tab2". Of course, they still remain two completely separated arrays. it simply copies "tab1" into "tab2", but "tab1" and "tab2" will still live their own life separately. If we modify "tab1", "tab2" will naturally not be impacted. As you can see, the utilization of arrays is very similar to the one of "vectors". The sole difference is that the size of "arrays" is fixed from the start and cannot be modified. Similarly, while we could build "vectors" of "vectors", we can also build "arrays" of "arrays" : static arrays of static arrays. Then, if need be we can of course combine the two : building static arrays of vectors, vectors of static arrays and so on. Now, let us have look at static arrays of static arrays, "arrays" of "arrays". What we did for "vectors" of "vectors", we can do for "arrays" of "arrays". The only difference is that we will have to indicate the sizes. For example, we can have an "array" of 2... Of two what? Of two "arrays" of two doubles. We thus have a matrix which we will call "rotation". This is a matrix we are wont to represent as a 2x2 arrays containing 4 elements. It is indeed an array of two "arrays of two doubles". Here is the declaration of a 2x2 static array. Of course, we can come up with many other examples. We could build an array collecting statistics on the districts. We will thus have the first-dimensional array containing the districts. Its size being the number of districts. Then, each districts will itself have a certain number of statistics. For example, two statistics such as the surface and the number of inhabitants. We can even build more complicated objects. such as three-dimensional arrays : arrays of arrays of arrays. Mathematically, this corresponds to tensors. What matters is to truly understand the different sizes. We will have an array of 3, of 3 arrays of 2, arrays of 2, arrays of 4 elements. This layer of 2 * 4 elements is reproduced three times in the initial array. Certainly, this is rather complicated and uncommon. The goal is to simply show that we may generalize to virtually any number of arrays and mostly to indicate the order of the different sizes. Let us now illustrate the use of these multi-dimensional arrays. Let us go back to what we had called the "rotation" matrix. It is 2x2 array of doubles which we represent like this. The utilization is exactly similar to the one of the "vectors". We will use the the brackets with two dimensions. Let us look at "rotation" of 1. Please remember that the size notation starts with 0 and ends with "size - 1". Here, we have rotation[1] In "rotation" of 1, we will seach for the element at the position 0. To this element here, we will give the value 0.231 . Here, we are indeed focusing on the element : " rotation[1][0] " Similarly, let us go back to our array of statistics Here, " statistique[i] " is thus an *array" containing "nb_statistiques" ints. It is an "array" of "nb_statistiques" integers. Itself, is an array which size is "nb_statistiques". This is rigorously similar to how we used to proceed with vectors of vectors. Nothing new here, except that the sizes are fixed. All rows thus have the same size/length. However, a little specifity in comparison to "vectors". This regards the initialization of "arrays" of "arrays". The syntax currently suppored by the compilers only tolerates one single brace in the initializations. For example, if we build a static array of static array, for example, 4 times 3 integers. Here, we are putting integers we wish to initialize. Unlike vectors, we will have to initialize simply with one single brace. Inside, we will put the set of values we wish to declare, in the reading order. Here, for example, 0, 1, 2 and then 3, 4, 5 simply separated by commas. Voilà , this is the syntax currently used to initialize static arrays of static arrays. To conclude, let us sum up the different syntaxes between static arrays and dynamic arrays, between "arrays" and "vectors". The size of dynamic arrays can vary while the program is being executed. On the other hand, the size of static arrays must be known while we are writing the program. The dynamic arrays are of the type "vector". The static arrays are of the type "array". When we declare a dynamic we can declare it empty - it is fully possible to declare an empty dynamic array - or we can give it an initial size, for example, 5. However, this size may vary during the course of the program. We can very well add or remove elements. For static arrays, the size must absolutely be known. We can either write it like this, or use a variable. One way or the other, this size must absolutely be known. Here, we only have one syntax for static arrays. Then, in order to use the elements of an array, the syntax is the same for static or dynamic arrays. For one dimension : " tab[i] ". If the array has two dimensions : " tab[i][j] " In order to know the size of an array, static or dynamic, we use the function "size". In order to go through an array, dynamic or static, we proceed the same way : we can either use a classical "for" loop or use a C++-11 loop with the colons. If we wish to go through the array without modifying the elements, we will write "for auto" followed by the name we wish to use for the elements. If we wish to modify the elements, we should not forget to add the ampersand ('&'). This is the same for a static array or a dynamic array. Then, in a dynamic array, we may possibly add elements. This is only possible for dynamic arrays and does not exist for static arrays. We cannot modify a static array. For dynamic arrays, we add elements with "push_back". This will add the value we have given to "x" at the end of the array. We will thus copy "x" at the end of the array. If we wish to remove the last element of a dynamic array, then, we will use "pop_back". Of course, this does not exist for static arrays since we cannot modify them. Finally, a last difference, regarding the initialization of dynamic arrays of dynamic arrays. We can use the syntax supported by all compilers of the initialization with an array of arrays between parentheses. For static arrays of static arrays, we will have to use the "equals" syntax with only one level of braces with the list of the desired values. Like this. One behind the other.