create an array in c++

Posted under C++ Course On By mohammed.mutawe

create an array in c++

Array, is a specific place in memory, which is reserved from a variable that contains a specified number of places and addresses of reservation within memory, and it is called Array.

Reasons for using

The use of Arrays is due to the need to organize and coordinate memory well, in addition to saving time.

For example, when defining 3 variables, int a = 5, int b = 1, int c = 6, this is a waste of time compared to the matrix in which all those variables are placed in the form of {6, 5, 1} = int arr [3].


Get the values ​​of the matrix

The way to print or read the Array is different from other methods for defining and reading variables. For example, when printing a variable of type int a = 6, we call this variable by name inside the editor, but when printing the variables inside the array arr above, we make an iterative loop that visits each Index of the array and fetch data from it.

Is the index the same as the value defined in the array?

Of course isn’t, Index is the memory tank that contains the location and address of those variables in memory, while the values ​​of these variables we specify freely.


Can we change the position of the index or the addresses of these variables in the Array?

Yes, we can, but we need to use indicators or the so-called Pointers in this procedure.



Please, for a better understanding of the Matrices, copy the following code into your code editor.

using namespace std;
int main() {
int a[4];
cout << "Please Enter Values : \n";
for (int i = 0; i <= 3; i++) {
cin >> a[i];
cout << "We Have Finished Fill Array\n";
for (int i = 0; i < 4; i++) {
cout << "Inserted " << a[i] << endl;
return 0;



Leave a comment

Your email address will not be published. Required fields are marked *