Arrays are declared as follows:
int p[5]; float temp[30]; char a[7];
The quantity mentioned inside the parenthesis denotes the subscript and it takes non-negative values. p[5] denotes that the range for the subscripts is 0..4 and that the array elements are p[0] …. p[4]. The first declaration int informs the compiler that the elements of the array named p can take only integer values and the second and third declarations inform the compiler that the elements of the array temp can take float values and the elements of the array a can take character values.
Following are some examples to illustrate the use of one-dimensional arrays.
Example
The program inputs the salary of 10 employees and finds the enhanced salary of employees with 15% raise in their salaries.
#include<iostream.h> #include<conio.h> void main() { float emp_sal[10],newemp_sal[10]; clrscr(); cout<<"Enter 10 Numbers : "; for(int i=0;i<10;i++) { cin>>emp_sal[i]; } for(i=0;i<10;i++) { newemp_sal[i] = ( emp_sal[i] *1.15); cout << newemp_sal[i]<<" " ; } getch(); }