ProgrammingHardHCL · Tech Mahindra pattern

What happens when this runs?

What happens when this runs?
int divide(int a, int b) {
    return a / b;
}
int main(void) {
    printf("%d", divide(10, 0));
}
  1. A. Undefined behaviour: integer division by zero
  2. B. Infinity, like floating-point division by zero
  3. C. Compile-time error: division by a literal 0 is caught by the compiler
  4. D. 0, since C treats x/0 as x

Correct answer: A. Undefined behaviour: integer division by zero

Unlike floating-point division (which has a well-defined IEEE-754 notion of infinity/NaN for x/0.0), integer division by zero has no such definition in C and is undefined behaviour — in practice it typically raises a hardware trap (SIGFPE on many systems), terminating the program, but this is implementation-specific, not guaranteed by the standard.

More C Programming questions

Exams that ask this topic