c++ - 关于C语言块作用域于for循环,本人小白
迷茫
迷茫 2017-04-17 15:26:03
0
4
559

请问如下代码:
for(int i = 1;i <= 5;i++)
{

 i = i;

}

其中定义的i属于块作用域吗?i的作用域是?为啥我在某些编译器能过,有些就不能过呢?求教大神

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(4)
小葫芦

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.

小葫芦

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.

小葫芦

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

小葫芦

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template