Does anyone know the reason why the variables have to be defined at the top of function

前端 未结 5 902
遥遥无期
遥遥无期 2021-02-09 14:18

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

5条回答
  •  一个人的身影
    2021-02-09 14:53

    You can do this in C so long as you use a C99 compiler. The restriction was lifted in C99.

    Presumably the restriction was originally there because compilers were less capable, or perhaps simply because nobody thought of allowing such a convenience for the programmer.

    When answering a question like this it is sometimes worth turning it around. Why would the original designers of C have done it the other way? They didn't have C++ to guide them!

提交回复
热议问题