Need help understanding this for loop code in C

后端 未结 5 1291
孤城傲影
孤城傲影 2021-01-11 17:22

Consider the following code in C:

void main()
{
    int a=0;

    for(printf(\"\\nA\"); a; printf(\"\\nB\"));

    printf(\"\\nC\");
    printf(\"\\nD\");            


        
5条回答
  •  死守一世寂寞
    2021-01-11 17:43

    What is the full "for" loop syntax in C (and others in case they are compatible)?

    This question quotes the applicable part of the standard. The 3rd expression shouldn't be evaluated unless the loop executes at least once. So, I'd say that in the 2nd case the old compiler is wrong to print 'B'.

提交回复
热议问题