Arrays und Vektoren in C++?
Ich bin noch ein Programmieranfänger und lerne C++
Die Grundlegenden Sachen wie Datentypen, In-Output, If-Abfragen, for-Schleifen und Switch-Case.
Aber bei Arrays und Vektoren bekomme ich Probleme vielleicht kann ich auch einfach nicht genug logisch denken dann mir trotzdem jemand helfen
Consider arrays as a collection of variables of the same type. The number is already set from the beginning (i.e. the collection can no longer be reduced or enlarged later) and each entry can be addressed via an index starting with the count at 0.
Example:
Here an array is created which can record five integers. Consequently, the index range is between 0 and 4 (both limits inclusive).
Only the first two entries are set. The value of the first entry is output.
If you already know the values of the entries from the start, you can also create the array as follows:
The indication of the size can be omitted in this case, because the compiler can now determine the number of elements themselves.
A vector is similar to an array. However, the number of acceptable values can be extended subsequently/dynamically.
Example:
At the beginning, the vector has a capacitance of 0. With adding the two values, it rises to two.
In short, arrays are static and cannot have expanded. You have a fixed size.
Vectors are dynamic and can be expanded as desired.