相关疑难解决方法(0)

int除以unsigned int导致翻转

我尝试用unsigned int划分int,我得到意想不到的结果:

int b;
unsigned int c;
int res;
float res_f;

b = -25;
c = 5;

res = b / c;   // res = 858993454
res_f = b / c; // res_f = -5.000000
Run Code Online (Sandbox Code Playgroud)

同样适用于'+',' - '和'*',但是'/'失败.我想念的是什么?

PS

它在不同的编译器上进行了测试,结果是一样的.

c arithmetic-expressions

5
推荐指数
1
解决办法
5444
查看次数

标签 统计

arithmetic-expressions ×1

c ×1