When reading any beginning manual on C++ an array is introduced as follows:
That format is valid, in that it compiles and seems to work just fine -- for a while.
Later on in the manual we learn to allocate/release memory using the new and delete keywords. So, the same array would be:
float * A = new float;
Now, the question is: When does it become necessary to allocate memory for an array?
I've seen code snipets of some fairly complicated algorithms, that make use of the simpler version of array declaration. But I wonder. If that algorithm is used as a function and called only once or twice, I guess it's no big deal. But if the same function is called 1000 times or more will the program run out of memory?
If it is always bad practice to not allocate memory, then why does every C++ manual I have ever seen introduce arrays without mentioning memory allocation? I have been criticized to re-read the instructional manuals more carefully whenever I have failed to allocate memory for arrays. But, I have never seen an instructional manual that introduces arrays and memory allocatation at the same time. They are always mentioned in two separate chapters, and memory allocation usually appear towards the end as a "more advanced" coding techinque (usually next to chapters on classes and templates) which implies that allocation is not always necessary. But, reading the advice on this forum I get the impression that it is.
So, when is is absolutely necessary to allocate memory and when is it ok not to do so?
Is there some guideline, or rule, for this?