
1 moroumo 2013-06-17 10:05:42 +08:00 程序是按照代码的顺序由上到下执行的。 既然你调换了顺序,当然结果就是不同的了。 |
2 xunyu 2013-06-17 10:12:26 +08:00 fathoms 没赋值的话是随机数, |
3 LokiSharp 2013-06-17 10:13:22 +08:00 对调一下的话,因为 fathoms 在使用前没有初始化,你能得到的只有一串没有意义的随机数 |
4 ETiV 2013-06-17 13:23:51 +08:00 int feet, fathoms; feet = 6 * fathoms; fathoms = 2; 如果编译的时候没报warning, 建议你换一个C的环境. |
5 Golevka 2013-06-17 13:27:44 +08:00 教练我想要隔壁ML家的val-binding =v= |
7 bengol 2013-06-17 14:45:17 +08:00 http://www.tenouk.com/Bufferoverflowc/Bufferoverflow2a.html details on function call, including how the local variables are initialized. |
9 detailyang 2013-06-17 17:24:57 +08:00 我习惯声明 变量时初始化...即便是0 |
10 jedyu 2013-06-17 17:31:45 +08:00 楼主骗分 |
12 clowwindy 2013-06-17 21:42:10 +08:00 $ gcc -Wall main.c main.c: 在函数‘main’中: main.c:7:8: 警告:此函数中的‘fathoms’在使用前未初始化 $ clang -Wall main.c main.c:7:14: warning: variable 'fathoms' is uninitialized when used here [-Wuninitialized] feet = 6 * fathoms; ^~~~~~~ main.c:4:14: note: initialize the variable 'fathoms' to silence this warning int fathoms; ^ = 0 1 warning generated. $ clang --analyze main.c main.c:7:12: warning: The right operand of '*' is a garbage value feet = 6 * fathoms; ^ ~~~~~~~ 1 warning generated. |