-2147483648*54 等于0为什么?

布鲁克零三四四 2015-07-06 11:54:14
vc2012的测试结果
我太烦了
...全文
314 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-05-09
  • 打赏
  • 举报
回复
在现实世界中,除时间和空间可能是无限的以外,其它任何事物都是有限的。
ztenv 版主 2016-05-09
  • 打赏
  • 举报
回复
的确是溢出惹的祸,
ArthurJava 2016-05-09
  • 打赏
  • 举报
回复
引用 9 楼 brook0344 的回复:
不是输出的问题,我是if语句判断出它等于零,在调试器里也看见它是零,不是输出的问题 给变量赋值也是零
溢出,-2147483648*54在存储时就溢出了,调试器自然是零
paschen 版主 2016-05-09
  • 打赏
  • 举报
回复
因为溢出了,溢出后变成了几那得看运算后的低32位值是什么
  • 打赏
  • 举报
回复
不是输出的问题,我是if语句判断出它等于零,在调试器里也看见它是零,不是输出的问题 给变量赋值也是零
赵4老师 2015-07-07
  • 打赏
  • 举报
回复
printf里面的%和变量的一一对应关系 scanf里面的%和变量以及变量前加不加&的一一对应关系 是C代码中非常容易出错的地方,而且通常编译还不出错。 所以在编译源代码之前值得专门仔细检查一遍甚至多遍。
赵4老师 2015-07-07
  • 打赏
  • 举报
回复
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/dv_vccrt/html/664b1717-2760-4c61-bd9c-22eee618d825.htm Collapse AllExpand All Code: All Code: Multiple Code: Visual Basic Code: C# Code: Visual C++ Code: J# Code: JScript Visual Basic C# Visual C++ J# JScript Run-Time Library Reference Format Specification Fields: printf and wprintf Functions See Also Send Feedback This topic describes the syntax for format specifications fields, used in printf, wprintf and related functions. More secured versions of these functions are available, see printf_s, _printf_s_l, wprintf_s, _wprintf_s_l. For details on the individual functions, see the documentation for those specific functions. For a complete listing of these functions, see Stream I/O. A format specification, which consists of optional and required fields, has the following form: %[flags] [width] [.precision] [{h | l | ll | I | I32 | I64}]type Each field of the format specification is a single character or a number signifying a particular format option. The simplest format specification contains only the percent sign and a type character (for example, %s). If a percent sign is followed by a character that has no meaning as a format field, the character is copied to stdout. For example, to print a percent-sign character, use %%. The optional fields, which appear before the type character, control other aspects of the formatting, as follows: type Required character that determines whether the associated argument is interpreted as a character, a string, or a number (see the "printf Type Field Characters" table in printf Type Field Characters). flags Optional character or characters that control justification of output and printing of signs, blanks, decimal points, and octal and hexadecimal prefixes (see the "Flag Characters" table in Flag Directives). More than one flag can appear in a format specification. width Optional number that specifies the minimum number of characters output (see printf Width Specification). precision Optional number that specifies the maximum number of characters printed for all or part of the output field, or the minimum number of digits printed for integer values (see the "How Precision Values Affect Type" table in Precision Specification). h| l| ll| I| I32| I64 Optional prefixes to type-that specify the size of argument (see the "Size Prefixes" table in Size and Distance Specification). Security Note: Ensure that format specification strings are not user-defined. For example, consider a program that prompts the user to enter his name and stores the input in a string variable called name. To print name, do not do this: Copy Code printf( name ); // Danger! If name contains "%s", program will crash Note: Instead, do this: Copy Code printf( "%s", name ); See Also Concepts printf, _printf_l, wprintf, _wprintf_l printf_s, _printf_s_l, wprintf_s, _wprintf_s_l printf_p Positional Parameters Send feedback on this topic to Microsoft.
勤奋的小游侠 2015-07-07
  • 打赏
  • 举报
回复
int溢出?printf("%d")? 换成long long试一下
lin5161678 2015-07-07
  • 打赏
  • 举报
回复
不能用 %d 输出求值结果 因为 -2147483648 的数据类型是 long long 这个数据类型的格式控制符和 int 是不一样的
fly_dragon_fly 2015-07-07
  • 打赏
  • 举报
回复
超过32位了, 要使用long long , -2147483648ll*54
ztenv 版主 2015-07-07
  • 打赏
  • 举报
回复
强转成更长的存储类型试试,
GKatHere 2015-07-07
  • 打赏
  • 举报
回复
未必 cout << (long long)-2147483648*54 ;
三楚雄风 2015-07-06
  • 打赏
  • 举报
回复

64,639

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧