An array is a collection of the same data type elements that share a common name in c++.
Types of Array in c++:
- One – dimensional arrays
- Two – dimensional arrays
1) ONE – DIMENSIONAL ARRAY
A list of items can be given one variable name using only one subscript and such a variable is called a single–subscripted variable or a one – dimensional array.
Like any other variables, arrays must be declared before they are used. The general form of array declaration is :
The syntax of ONE – DIMENSIONAL ARRAY is :
datatype array_name[sizeofarray];
The datatype specifies the type of element that will be contained in the array, such as int, float, or char.
The size indicates the maximum number of elements that can be stored inside the array.
The size of the array should be a constant value.
The Example of ONE – DIMENSIONAL ARRAY is :
float height[50];
#include <iostream> #include <conio.h> using namespace std; main() {   int num[5] = {3, 5, 6, 7, 3};   //  index   0  1  2  3  4   cout << "Element of 3 index is " << num[3];   getch();   return (0); }
output
Element of 3 index is 7
Also Read This :- conditional statement in c++. | if else, nested if-else, switch case
2) Two – DIMENSIONAL ARRAY
A list of items can be given one variable name using two subscripts and such a variable is called a two – subscripted variable or a two – dimensional array.
The syntax of TWO – DIMENSIONAL ARRAY is :
data_type array_name[row size] [column size] ;
The Example of TWO – DIMENSIONAL ARRAY is :
int V[5][3];
#include <iostream> #include <conio.h> using namespace std; main() {   int num[2][5] = {             {3, 5, 6, 7, 3}, // 0             {1, 2, 4, 9, 8}  // 1       //  index   0  1  2  3  4           };   cout << "Element of [0][3] index is " << num[1][3];   getch();   return (0); }
output
Element of [0][3] index is 9