All this time I have been declaring variables inside loops without blinking an eyelid, assuming that compilers will always do the necessary optimization and not reallocate the memory for a variable for each iteration of the loop. Imagine my surprise on reading the following from the "C Bible" (K&R), Section 4.8 Block Structure
:
An automatic variable declared and initialized in a block is initialized each time the block is entered.
So is K&R outdated, or is it a wrong assumption the compilers will always do the necessary optimization to ensure that memory allocation for a variable declared in a loop is done only once?