Declaration of 1-Dimensional Arrays:
In order to use the array in your programming, you must provide the following information to compiler of C++ you use in your computer.
1. The name of the array and it should not be an reserved keyword of C++ language.
2. Total number of element to be stored in the array at the time of its use.
3. Total number of memory location to be reserve.
Example: Data_type_name array_name[size];
where Data_type_name is a user defined name which they want to use like int, float, double etc.
array_name is the name of the array given by the user and it can't be a reserved key words of C++ language and size is the given element size of the variable.
Program: Write a program to initialize and print an array element.
#include<iostream.h>
int main()
{
int array[6] = {1, 2, 3,4 ,5 6 };
cout<<"The array element stored in array are: ";
for(int j=0; j<6; j++)
{
cout<<array[j]<<" ";
}
return 0;
}
In the above program we are declare a variable array[6] with its 6 values and we print these value using for loop.
Output:
The array element stored in array are: 1 2 3 4 5 6
Thanks
Mukesh Rajput
Post A Comment:
0 comments: