栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

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

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

复制代码 代码如下:
#include
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);
}

复制代码 代码如下:
#include
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);
}

gcc编译后:
int_sizeof1.c: 在函数‘main'中:
int_sizeof1.c:5: 警告:整数溢出
运行后:
The max value of int on 32 machine: 4294967295
 
VC6.0和java编译后,无错误。
运行后:
The max value of int on 32 machine: 4294967295
复制代码 代码如下:
#include
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);
}

将其int写成有符号型的程序如下:
复制代码 代码如下:
#include
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);
}

gcc编译后:
int_sizeof1.c: 在函数‘main'中:
int_sizeof1.c:5: 警告:整数溢出
运行后:
The max value of int on 32 machine: 2147483647
VC6.0和java编译后,无错误。
运行后:
The max value of int on 32 machine: 2147483647
因为int的最高位是符号位。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/66432.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号