A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/cstdlib/div/ below:

function

<cstdlib>

div
div_t div (int numer, int denom);
 div_t div (     int numer,      int denom);ldiv_t div (long int numer, long int denom);
  div_t div (          int numer,           int denom); ldiv_t div (     long int numer,      long int denom);lldiv_t div (long long int numer, long long int denom);

Integral division

Returns the integral quotient and remainder of the division of numer by denom ( numer/denom ) as a structure of type div_t, ldiv_t or lldiv_t, which has two members: quot and rem.

Parameters
numer
Numerator.
denom
Denominator.

Return Value The result is returned by value in a structure defined in <cstdlib>, which has two members. For div_t, these are, in either order:
1
2
int quot;   // quotient
int rem;    // remainder 

Portability In C, only the int version exists.
For the long int equivalent, see ldiv.
For the long long int equivalent, see lldiv.

Example
1
2
3
4
5
6
7
8
9
10
11
/* div example */
#include <stdio.h>      /* printf */
#include <stdlib.h>     /* div, div_t */

int main ()
{
  div_t divresult;
  divresult = div (38,5);
  printf ("38 div 5 => %d, remainder %d.\n", divresult.quot, divresult.rem);
  return 0;
}

Output:
38 div 5 => 7, remainder 3.


Data races Concurrently calling this function is safe, causing no data races.

Exceptions (C++)No-throw guarantee: this function throws no exceptions.

If either part of the result cannot be represented, it causes undefined behavior.



See also
ldiv
Integral division (function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4