Mail Archives: djgpp/2000/08/10/10:45:35
Vermin <ratspl AT hotmail DOT com> wrote:
> <1>
> What's the difference between
> char anArray[100];
> and
> char *anArray;
> anArray = new (char)[100];
Place of storage, and lifetime of the array. The first creates an
array that lives on the stack, until you leave the block the
definition is found in (or in a global data segment until program
termination, if it's at file scope), the second creates a block that
exists until you delete[] it, and a pointer to it with a certain
lifetime.
> <2> How can I pass an array with undefined size to a procedure, and
> get the procedure to set the array size (C++)??
You can't. Array size isn't modifiable a posteriori. You can only
change the size of "new"ed arrays, and that only by delete[]ing them
and "new"ing a new one.
If you need a truly variable-sized array, look up the 'vector' template.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -