请问如下代码:
for(int i = 1;i <= 5;i++)
{
i = i;
}
其中定义的i属于块作用域吗?i的作用域是?为啥我在某些编译器能过,有些就不能过呢?求教大神
高洛峰2017-04-17 15:28:03
This syntax is not standard syntax, and there is no guarantee that all compilers can compile this sentence, but if it can be compiled, i belongs to the block scope.
高洛峰2017-04-17 15:28:03
It should be a compiler problem. VS2010 may use the c90 standard. C90 does not allow direct declaration of int i=0 in for. Int i must be declared at the beginning of the program. C99 supports writing for like this. If it fails to compile, this may be the problem.
高洛峰2017-04-17 15:28:03
In the gcc compiler, the c language must first define a statement before it can be called. The mingw compiler can declare variables anywhere in the middle of the code
高洛峰2017-04-17 15:28:03
Non-standard syntax, compilers are different, and the results are not uniform. However, this question does not make sense. Modifying loop variables in the loop body is against programming standards