-
Dynamica arrays in C
hi ppl,
i know there's a lot of talent out there, so i am challenging UR talent. HA HA HA ....
is there any way to simulate dynamic arrays in C, or C++.
i really need that..
and hay , not the linked lists and other things,,,, some piece of code that can enable me to make dynamic arrays just like i do it in VB.......( who says C language is powerful ).
Salman.
-
To dynamically allocate an array (at rub time):
Code:
int myarray = new int[size];
To change the array size in runtime use the vector class.
-
The vector can also be used to do preserve the data.
Code:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> myVect;
// Append 4 and 5
myVect.push_back(4);
myVect.push_back(5);
// Resize to 20;
myVect.resize(20);
// Output the ubound
cout << myVect.size();
return 0;
}