C Compiler Logo

Floating Point Exception

Floating Point Exception

runtime

Floating point exception (core dumped)

Description

The program performed an invalid floating-point operation, such as division by zero.

Common Causes

Example of Error

Error Code

int main() {
    int a = 10;
    int b = 0;
    int result = a / b;  // Division by zero
    return 0;
}

Solution

Check for zero values before performing division or modulo operations.

Corrected Code

#include <stdio.h>

int main() {
    int a = 10;
    int b = 0;
    int result;

    if (b != 0) {
        result = a / b;
    } else {
        printf("Error: Division by zero\n");
        result = 0;  // Or some other appropriate value
    }

    return 0;
}

Additional Tips