小编Sid*_*oor的帖子

为什么“INT_MAX * INT_MAX”乘积给出 1?

我正在学习计算机体系结构,并决定尝试乘法溢出。观察到 的溢出INT_MAX * INT_MAX,但我不确定为什么这会在 C/C++ 中给出乘积 1。

#include <stdio.h>
#include <limits.h>

int main()
{
    int num = INT_MAX;
    printf("%0x\n", num);       //stdout is 0x7fffffff
    printf("%d\n", num * num);  //stdout is 1
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c integer-overflow cpu-architecture

2
推荐指数
1
解决办法
282
查看次数

标签 统计

c ×1

cpu-architecture ×1

integer-overflow ×1