C & C++

C & C++

Made by DeepSource

Potential divide by zero CXX-W1264

Bug risk
Major

Dividing by zero can cause a runtime error, leading to a crash. Because as such dividing by zero is undefined behaviour.

Dividing by zero on UNIX environments will crash the program due to a SIGFPE signal.

Bad practice

int x = 10 / 0; // is likely a mistake
int y = 0; // is likely a mistake
int z = 1 / y;

Recommended

int x = 10 / 1;
int y = 1;
int z = 1 / y;

References