Popular Google Pages:
◕ Send a story and get ₹ 200/- More..
◕ Bengali Story writing competition. More..
◕ This article is regarding Array in C++.
Last updated on: 03rd May 2017.
◕ What is an array in C++?
An array is a data form in C++. This can hold several values of the same type.
In a class room there are 50 students.
We are making two arrays.
1. int student;
Here the array student is holding 50 different values of int type that represent the roll number of every student in a class room.
2. float weight;
Here the array weight is holding 20 different values of the float type that represents the weight of 20 different students in a class room.
◕ What is array element?
Arrays are made with the elements.
This means, each of the above mentioned values of the arrays are stored in separate elements.
The computer stores all the elements of an array consecutively in its memory.
This array contains 20 elements. The elements are:
weight, weight, weight... weight, weight
The serial number of the element always starts from 0, not from 1.
◕ How to create an array?
Let have the examples first.
Here we are declaring two arrays.
■ 1st example:
The name of the array is student.
It has 50 elements.
Each element contains the age of a student.
■ 2nd example:
The name of the array is weight.
It has 20 elements.
Each element contains the weight of a student.
Hence to create an array, we should declare a statement.
This array declaration consist three things.
1. The type of value to be stored in each element i.e. typeName.
2. The name of the array i.e. arrayName.
3. The number of the elements in the array i.e. arraySize.
The general declaration of an array is
1. The arraySize must be an integer i.e. a constant value.
2. The arraySize can also be an expression like 2+sizeof(int).
But the result of the expression must be an integer.
How to display a value in Hexadecimal form in C++?
How C++ identify the base of a number?
Symbolic Constant in C++
Top of the page