Well,you can create a dynamic array and gives it any size that you want while the program is running.
Here is an example of it.
#include <iostream.h>
void main()
{
float *array;
int size;
cout<<"\t\tStoring data in an array."<<endl<<endl;
cout<<"How long will be your array ?"<<endl;
cin>>size;
array = new float[size]; // allocating memory to the array
for( int i = 0; i < size; i++ )
{
cout<<"array["<<i<<"] = ";
cin>>array;
}
cout<<"This new array have been created !"<<endl;
cout<<"array["<<size<<"] = {";
for( i = 0; i < size; i++ )
{
cout<<array;
if( i < size - 1 )
cout<<",";
}
cout<<"} ";
delete array; // freeing memory
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.