how can I check integer overflow in C/C++?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to know how to determine overflow in C/C++. if my input for integer is 9999999999999999999999 , It is a very big number and if I run the below code I will get a garbage output. #include <stdio.h> int main(){ int a; scanf("%d",&a); printf("%d",a); return 0; } Is there any way to know , if the input is a big number, I can output "Input is too big" . Note that, I have already checked How to detect integer overflow? . But the question is different from my one. 回答1: In your case, read the input in a string and then, depending of the length