源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

求32位机器上unsigned int的最大值及int的最大值的解决方法

  • 时间:2022-07-18 14:08 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:求32位机器上unsigned int的最大值及int的最大值的解决方法
[u]复制代码[/u] 代码如下:
#include <stdio.h> int main(int argc, char *argv[]) {  unsigned int max_int = 0-1;  printf("The max value of unsigned int on 32 machine: %u/n", max_int); }
[u]复制代码[/u] 代码如下:
#include <stdio.h> int main(int argc, char *argv[]) {  unsigned int max_int = 0-1;  printf("The max value of unsigned int on 32 machine: %u/n", max_int); }
[b]gcc编译后: [/b]int_sizeof1.c: 在函数‘main'中: int_sizeof1.c:5: 警告:整数溢出 [b]运行后: [/b]The max value of int on 32 machine: 4294967295   [b]VC6.0和java编译后,无错误。 运行后: [/b]The max value of int on 32 machine: 4294967295
[u]复制代码[/u] 代码如下:
#include <stdio.h> int main(int argc, char *argv[]) {  int max_int = (1<<31)-1;  printf("The max value of int on 32 machine: %d/n", max_int); }
[b]将其int写成有符号型的程序如下: [/b]
[u]复制代码[/u] 代码如下:
#include <stdio.h> int main(int argc, char *argv[]) {  int max_int = (1<<31)-1;  printf("The max value of int on 32 machine: %d/n", max_int); }
[b]gcc编译后: [/b]int_sizeof1.c: 在函数‘main'中: int_sizeof1.c:5: 警告:整数溢出 [b]运行后: [/b]The max value of int on 32 machine: 2147483647 VC6.0和java编译后,无错误。 [b]运行后: [/b]The max value of int on 32 machine: 2147483647 因为int的最高位是符号位。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部