当前位置:网站首页>整数乘以整数溢出了
整数乘以整数溢出了
2022-07-23 05:45:00 【18阿鲁】
先看一个例子,将两个32位的Int型数相乘,将结果赋给long型变量。long a=111111 * 111111;
乍一看好像没毛病,但这是个坑,慎跳!相乘以后的值会溢出。
原因:
对于编译器来说,int和int相乘,结果也是先存在int中,跟被赋给long还是longlong数据类型的字段没有关系。
解决办法:
想要不溢出,就要把两个32位数强制转换成long类型,再相乘。
边栏推荐
- Related repo of synthetic Chinese recognition dataset
- Mutual implementation of queue and heap (pure C implementation)
- [introduction to AUTOSAR com 4.com service layer module]
- C语言基础练习题初学者可参考
- [AUTOSAR com 2. Advanced introduction to communication protocol stack]
- Prometheus
- 广播,组播,单播
- 5.4 installation and use of pyinstaller Library
- 第一篇试水--*offer
- linkerd服务网格调研笔记
猜你喜欢

Knowledge structure of advanced algebra
Blog Building III: comment system selection

【Autosar DEM 四.Event Memory】

【无标题】

【基于UDS服务的BootLoader架构和刷写流程】

Interpretation of the paper: recognition of enhancer promoter interactions with neural networks based on pre trained DNA vectors and attention mechanisms

C language small project - student achievement management system

用单向链表实现 队列

OSI开放系统互联模型和TCP/IP模型

A comprehensive and detailed summary of the basic principles of steel structure
随机推荐
Unity3D高清渲染管线无法在模型上播放视频
【AUTOSAR COM 1.通信协议栈介绍】
博客搭建一:框架选择
基于UDP的群聊聊天室
合成中文识别数据集的相关repo
Doubts about using the incluxdb database
Embedded from entry to mastery (buried) - sharing of ultra detailed knowledge points 1
VS属性配置相关知识
Anonymous upper computer V7 waveform display
关于如何排查vpn服务器无法转发的问题
ThreadLocal到底在干嘛?
Analysis of 100 questions and answers in Higher Algebra
hot 100 动态规划
嵌入式从入门到精通(入土)——超详细知识点分享2
3.2daydayup举一反三:三天打鱼两天晒网式学习
《Kubernetes in Action》第二章笔记
快速排序的按区间的三个版本及优化--友友们不一定了解
LVS负载均衡调度原理及配置方法
【存储器了解 RAM flash和eeprom存储器的区别和作用】
动态规划——“换硬币问题”