在GCC编译器上工作时,针对C程序中以下两种运算符的情况观察到了不同的行为。
1.
并且,
2.
在第一个案例中,编译器给出了错误提示“error: expected identifier or ‘(’ before numeric constant”。在第二个案例中,没有错误,并且输出结果为1。有人可以在这里详细解释一下编译器两种情况下的行为吗?编译器如何解释这两个语句?
非常感谢您提供的意见。
1.
int i = 1,2,3;
printf("%d",i); // this will give compile time error
并且,
2.
int i;
i = 1,2,3;
printf("%d",i); // Its output will be 1.
在第一个案例中,编译器给出了错误提示“error: expected identifier or ‘(’ before numeric constant”。在第二个案例中,没有错误,并且输出结果为1。有人可以在这里详细解释一下编译器两种情况下的行为吗?编译器如何解释这两个语句?
非常感谢您提供的意见。
1
。 - haccks