Hello again.
Today I will be teaching you about arrays in C++. Arrays can store multiple values of the same data type. To declare an array we simply type the data type we want the array to be and then we type the array name then in square brackets we can type the size of the array although we can declare it without that as well. After that, we can assign values to that array in curly brackets. E.g. -
int arr[5] = {1,2,3,4,5};
This is an example of the length of the array written.
string arr1[] = {"Coding","with","Ammar"};
This is without the length of the array written. This array will automatically know what its size is because of the amount of content we have declared.
Within the arrays, there are two key information. The first one is the index and the second is the data. The latter one the data is the one you declare or assign in the array. The first one however is different, the index tells us the position of the data in the array. The array always starts with the index of 0 for the first data in the array. Just like in the example above "Coding" has an index of 0. If we want to get a specific element from the array then we can type it as -
cout << arr1[0];
This code will output only "Coding". But if we want to output the whole array then we have to use loops which I will discuss in my next post.
The associated video that I have posted.