I have a question, does anyone know why the variables have to be defined initialized at the beginning of a function? Why can\'t you initialize or define variables in the
That is a left-over from early C. C99 allows variables to be defined anywhere in the function, including in loop structures.
for (int i = 0; i < 10; ++i) { int j; }
The throwback is from when compilers needed to know the size of the stack for the function before they instantiated the function's code. As compilers became better the requirement just became annoying.