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.