Home › Forums › C Programming › Array Problem › Re: Re: Array Problem
February 21, 2010 at 10:09 pm
#3639
GWILouisaxwzkla
Participant
Unless theres a new C++ standard , you cannot declare arrays of an arbitrary length ( the length must be declared as a constant so the compiler knows how to set up the function’s stack frame at compile time ). So you can’t do this ( I’m suprised this compiled, what compiler are you using ?):
1 2 3 | <br /> int array [ g + 1 ];<br /> |
If you want a arbitrary length array you have to allocate it at run time , like:
1 2 3 | <br /> int * array = new int [ g + 1 ];<br /> |
make sure to check allocation of this statement and delete the memory when your done with it ( by the end of the function call )………