我的代码:为什么0%0会导致1?
long long difft, intrv ;
cout << "difft = " << difft << endl;
cout << "intrv = " << intrv << endl;
cout << "difft mod intrv = " << difft%intrv << endl;
输出:
difft = 0
intrv = 0
difft mod intrv = 1
的0%0的结果是零,但在我的代码,结果是 “1”,为什么呢?
尝试将您的值更改为非零 – Quest
在C++中没有任何解释的一切都是因为未定义的行为:) – Maroun
实际上,0%0是未定义的行为,因为您不能将其除以0。 – Netwave