C++ Arrays And Multidimensional Arrays

In this article we are going to talk about C++ Arrays And Multidimensional Arrays, so c++ arrays are collection of the elements that are the same type. if you remember our article on variables, when we want to store one value we are going to use variable. If we want to store two or three values we need to use more variables. but it is not a good way, by this reason we have arrays. also  the elements of array are stored in the continues memory location.

 

 

 

Also you can check more articles on c++ programming language

1: C++ Introduction & Program Structure 

2: C++ Variables And Data Types 

3: C++ Getting User Input 

4: C++ If Else Statement 

5: C++ Short Hand If Else

6: C++ Switch Statement 

7: C++ Loops Complete Example

 

 

 

 

So for creating of array , first of all you need to specify the data type of the array, in the second step you need to give a name for the array, and after that initialize the elements of the array.

 

 

For example we can write like this.

 

 

In the above example, we have also specified the length of the array, but it is optional, you can leave it blank like this.

 

 

So now if you want to access the specific element of the array, you need to use the array index of the element, and make note that the array index starts from the zero index.

 

 

 

This will be the result.

 

 

 

Also you can iterate over arrays using for loop like this.

 

 

 

This will be the result

 

 

 

Now let’s talk about multi dimensional array, a multidimensional array in C++ is really just an array of arrays. also a two-dimensional array is an array of arrays.  a two-dimensional array or 2D array is like a table with rows and columns.

 

 

So above code is a two dimensional array, where we have two rows and four columns, or also we can say that we have two arrays and there are four elements in each array. for accessing the element of multi dimensional array, first of all you need to specify the index of the array, and after that the index of the array element.

 

 

 

 

 

Also you can iterate over multi dimensional array like this.

 

 

 

 

This will be the result

 

 

 

 

Also you can watch the complete video for this article

 

Subscribe and Get Free Video Courses & Articles in your Email

 

1 thought on “C++ Arrays And Multidimensional Arrays”

Comments are closed.

Codeloop
Share via
Copy link
Powered by Social Snap
×