C++ Quiz20 of 173
Difficulty:
⬅️ Prev: 25Quiz ID: 26Next: 27 ➡️

According to the C++23 standard, what is the output of this program?

#include <iostream>

int main() {
  int i = 42;
  int j = 1;
  std::cout << i / --j;
}
Hint

What happens when you divide an integer by zero?

Reveal answer

The program is (or may be) undefined

Explanation

Integer division by zero is undefined behaviour. According to §[expr.mul]¶4 in the standard:

If the second operand of / or % is zero the behavior is undefined.

⬅️ Prev: 25Quiz ID: 26Next: 27 ➡️