表达式6 // 4得出1,其中除法在除数之后产生整数.
但是负数,为什么会-6 // 4回归-2呢?
在C++中,如果我打印一个尚未赋值的变量会怎样?以下两个代码给出了两个不同的结果.此外,第一个在每个编辑中给出不同的结果,第二个每次打印0.为什么?
int main() {
int x = 1;
int y; // No value has been assigned
if (x) {
cout << y; // without using endl
// prints different value each time
}
}
Run Code Online (Sandbox Code Playgroud)
与
int main() {
int x = 1;
int y; // y is not initialized
if (x) {
cout << y << endl; // using endl
// prints 0
}
}
Run Code Online (Sandbox Code Playgroud)