C++ Reference: Standard C++ Library reference: C Library: cstdlib: ldiv

C++官网参考链接:https://cplusplus.com/reference/cstdlib/ldiv/

函数 
<cstdlib>
ldiv
ldiv_t ldiv(long int numer, long int denom);
整数除法 
返回numer除以denomnumer/denom)的整数商和余数,作为ldiv_t类型的结构,它有两个成员:quot和rem。

形参 
numer
分子。 
denom
分母。

返回值
结果在一个ldiv_t结构中按值返回,该结构有两个成员(顺序不限):
long int quot;   // quotient
long int rem;    // remainder 

用例
/* ldiv example */
#include <stdio.h>      /* printf */
#include <stdlib.h>     /* ldiv, ldiv_t */

int main ()
{
  ldiv_t ldivresult;
  ldivresult = ldiv (1000000L,132L);
  printf ("1000000 div 132 => %ld, remainder %ld.\n", ldivresult.quot, ldivresult.rem);
  return 0;
}
输出:

数据竞争
同时调用此函数是安全的,不会导致数据竞争。

异常(C++) 
无抛出保证:此函数不抛出异常。
如果不能表示结果的任何一部分,就会导致未定义的行为。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_40186813

你的能量无可限量。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值