jun-csbio / CClass_ZJUT

CClass_ZJUT
1 stars 0 forks source link

定义变量与逗号语句的问题 #45

Open XiaoBaiBZS opened 1 year ago

XiaoBaiBZS commented 1 year ago
#include<stdio.h>
int main(){
    int j;
    for(int k=0,j=1;j<5;j++){
        printf("%d“,k);
    }
    return 0;
}

这种写法编译器不报错,但是换成如下写法,把int k=0和j=1换一下位置,编译器会报错,但是明明j之前就已经定义好了,为什么会报错?

#include<stdio.h>
int main(){
    int j;
    for(j=1,int k=0;j<5;j++){    //把int k=0和j=1换一下位置
        printf("%d",k);
    }
    return 0;
}

4 13 [Error] expected primary-expression before 'int' 5 21 [Error] 'k' was not declared in this scope