<!--
{
  "documentType" : "article",
  "framework" : "Xcode",
  "identifier" : "/documentation/Xcode/division-by-zero",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Division by zero"
}
-->

# Division by zero

Detects division where the divisor is zero.

## Overview

Use this check to detect integer and float division where the divisor is zero. Division by zero has undefined behavior, and can result in crashes or incorrect program output. Available in Xcode 9 and later.

### Integer division by zero in C

In the following code, the `for` loop performs division by zero on its first iteration:

```occ
int sum = 10;
for (int i = 0; i < 64; ++i) {
    sum /= i; // Error: division by zero on the first iteration
}
```

> Note: The optimizer may remove parts of a loop if it determines that undefined behavior might trigger in any of its iterations.

#### Solution

Modify the logic to check for and avoid division when the divisor might equal zero.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)