C 的复职位置问题...中程考试引起的


main()
{
int i;
double a,b;
a=10.333432;
b=2.34211;
/* 问题就在这里, 如果我把 int i 移到这个位置, 请注意是移动, 而不是重复定义. 那么程序立刻出错, 难道是BUG */
i = (int)a/b;
printf ("%f\n",a / b);
printf ("%d\n",i);
}
[267 byte] By [yanyading-向OOP转行的TurboBasic] at [2008-5-11]
# 1
C does not allow variable definition/declaration after the first execution statement. That is all the variable definition/declaration of a function must be put at the beginning.

C++ does not have this restriction.
do_do-do_do at 2007-10-26 > top of Msdn China Tech,C/C++,C语言...
# 2

变量定义要放在赋值前面

C不象C++
liaogs-夜归人 at 2007-10-26 > top of Msdn China Tech,C/C++,C语言...
# 3
不是吧?我用tc3。0可以通过啊???我刚才实验过了
zsyangel-乱世天使 at 2007-10-26 > top of Msdn China Tech,C/C++,C语言...
# 4
我是这样的
void main()
{
int a=23;
int b=33;
int i;
i=(int)a/b;
cout<<i;
}
zsyangel-乱世天使 at 2007-10-26 > top of Msdn China Tech,C/C++,C语言...
# 5
C++ 中可以这么干
C 中就不行

C 要求所有声明语句在实际可执行代码前
zheng_can-nothrow at 2007-10-26 > top of Msdn China Tech,C/C++,C语言...