手机
当前位置:查字典教程网 >编程开发 >C语言 >求32位机器上unsigned int的最大值及int的最大值的解决方法
求32位机器上unsigned int的最大值及int的最大值的解决方法
摘要:复制代码代码如下:#includeintmain(intargc,char*argv[]){unsignedintmax_int=0-1;p...

复制代码 代码如下:

#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);

}

复制代码 代码如下:

#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);

}

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 <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);

}

将其int写成有符号型的程序如下:

复制代码 代码如下:

#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);

}

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的最高位是符号位。

【求32位机器上unsigned int的最大值及int的最大值的解决方法】相关文章:

基于Sizeof与Strlen的区别以及联系的使用详解

SQL Server中的数据复制到的Access中的函数

求数组中最长递增子序列的解决方法

判断整数序列是否为二元查找树的后序遍历结果的解决方法

c语言中用字符串数组显示菜单的解决方法

深入C++浮点数无效值定义与判定的解决办法

将字符串str1复制为字符串str2的三种解决方法

C语言中判断int,long型等变量是否赋值的方法详解

c++ 一个二进制串转化为整数的解决方法

C/C++中退出线程的四种解决方法

精品推荐
分类导航