#2
Post
by BikerBoy » 08 Jan 2010 00:40
Variables are not normally allowed when declaring arrays because the compiler needs to know how big the array is so that it can allocate memory for the array.
Also variables are usually initialised to 0 by the compiler otherwise they could contain garbage this would mean that your array could start off any size!
The best way is to decide the maximum size you will need and initialise it that big, you don't need to use all the elements of the array
Usually a constant is used ie
#define ArrSz 128
int MyArray[ArrSz]; OR int MyArray[128];
or you can pass a parameter list and the compiler will work out the size ie
int MyArray[] = {1,2,3,4} //Results in MyArray having 4 elements.
Some languages VB6 being one allows you to change the size of an array at runtime but as far as I am aware C does not