<分区>
[我以为这个问题已经有人问过了,但我找不到答案]。
在编写 if
语句时,我要比较的东西应该放在第一位还是第二位? (我对 C/C++
和 Java
特别感兴趣)。
重要吗,还是只是风格? (惯例似乎是“首先是变量,其次是值”)。
考虑以下代码:
#include <iostream>
int main() {
int x = 5;
if ( 5 == x ) {
std::cout << "X == 5, true." << std::endl;
}
if ( x == 5 ) {
std::cout << "5 == X, true." << std::endl;
}
return 0;
}
哪些输出:
X == 5, true.
5 == X, true.
所以看起来没有任何区别。我缺少一些微妙之处吗?