> For the complete documentation index, see [llms.txt](https://42-guide.gitbook.io/42-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://42-guide.gitbook.io/42-guide/piscine-life/c01/ft_div_mod.md).

# ft\_div\_mod

**Objective:**

Create a function that divides two integers and stores both the quotient and the remainder in the memory locations provided by pointers.

**Turn-in Requirements:**

* **Directory**: `ex03/`
* **File**: `ft_div_mod.c`
* **Allowed Functions**: None

**Prototype:**

```c
ft_div_mod(int a, int b, int *div, int *mod);
```

**Implementation:**

Here’s how you can implement the function:

```c
// File: ft_div_mod.c
#include <unistd.h> // Optional, not needed for this task but can be standard practice for headers

void ft_div_mod(int a, int b, int *div, int *mod)
{
        *div = a / b; // Store the quotient in *div
        *mod = a % b; // Store the remainder in *mod
}
```

**Explanation:**

1. **Input Parameters**:
   * `a` and `b` are integers representing the dividend and divisor, respectively.
   * `div` is a pointer where the quotient will be stored.
   * `mod` is a pointer where the remainder will be stored.
2. **Division and Modulus**:
   * The function calculates the quotient (`a / b`) and stores it at the memory location pointed to by `div`.
   * Similarly, it calculates the remainder (`a % b`) and stores it at the location pointed to by `mod`.
3. **Error Handling**:
   * The function checks if `b` is not zero before performing the operations to avoid division by zero.

**Example Usage:**

```c
#include <stdio.h>

void ft_div_mod(int a, int b, int *div, int *mod);

int main()
{
    int a = 42;
    int b = 5;
    int quotient, remainder;

    ft_div_mod(a, b, &quotient, &remainder); // Pass addresses of quotient and remainder
    printf("Quotient: %d, Remainder: %d\n", quotient, remainder);

    return 0;
}
```

**Output:**

```yaml
Quotient: 8, Remainder: 2
```

**Notes:**

* If `b` is zero, the function does nothing. You can add additional error handling if required.
* This exercise demonstrates how to use pointers to return multiple values from a function.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://42-guide.gitbook.io/42-guide/piscine-life/c01/ft_div_mod.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
