Array in C++

Array in C++.

 

Array is one of the most useful concept of programming language , let`s talk little bit before starting with array.

Let`s suppose we have one integer type variable named as number1 but that`s not enough for our work then take one more variable named as number2 now we need one more variable to store our numbers come`on take one more variable named as number3. Now stop and think if you need to store 1000 numbers then what would you do? will you declare number variable 1000 times?. I know that your answer is no , for that we need a better solution , and that solution is array. Because an array can contain a list of data in itself.

 

What is array?

 

Array is just a collection of similar types of data items, when we need to store the same types of data in a single variable then we create an array and use it to store data. An array should be declare before the use just like other variables.

array in c++

What is array subscript.

 

Array subscript is notify the location of each array element in a array. Array subscript is start from 0 and ends on array_size – 1.

 

What is array element.

Array elements are the data which we stored in a array. Elements of a array always have same data type.

How to declare a array.

Let`s see the syntax of declaring a array in C++.

 

Syntax.

datatype array_name[Size];

In above syntax you can see that how to declare a array in C++.

 

Example.

 

int num[20];

In above example num is a integer type array , which can be store 20 elements.

Types of array in C++.

In C++ there are two types of arrays, are as follows.

  1. one dimensional array.
  2. Two dimensional array.