2 ms·
C, up through, C89, required variable declarations at the beginning of a block. C++ allowed them to be declared anywhere. This was popular enough that it was
by ksherlock 7y ago
C, up through, C89, required variable declarations at the beginning of a block. C++ allowed them to be declared anywhere. This was popular enough that it was added to C99 (along with // comments). There are some cases (references and objects without default constructors) where declaring at the start of a block might not be practical.
Best practice? Shrug. Declaring variables anywhere was a conscious decision.