This C++ Program demonstrates the implementation of Variable length array.
Here is source code of the C++ Program to demonstrate the implementation of Variable length array. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Implement Variable length array
*/
#include <iostream>
#include <string>
using namespace std;
int main()
{
int *array, size;
cout<<"Enter size of array: ";
cin>>size;
array = new int [size];
for (int i = 0; i < size; i++)
{
cout<<"Enter an integer to be inserted: ";
cin>>array[i];
}
for(int i = 0; i < size; i++)
{
cout<<array[i]<<" ";
}
cout<<endl;
delete []array;
return 0;
}
$ g++ variablelength_array.cpp $ a.out Enter size of array: 5 Enter an integer to be inserted: 3 Enter an integer to be inserted: 4 Enter an integer to be inserted: 2 Enter an integer to be inserted: 5 Enter an integer to be inserted: 1 3 4 2 5 1 ------------------ (program exited with code: 1) Press return to continue
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Check C++ Books
- Apply for C++ Internship
- Apply for Computer Science Internship
- Practice Programming MCQs
- Check Programming Books