求32位機器上unsigned int的最大值及int的最大值的解決方法
更新時間:2013年05月31日 17:35:45 作者:
本篇文章是對求32位機器上unsigned int的最大值及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);
}
復制代碼 代碼如下:
#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: 在函數(shù)‘main'中:
int_sizeof1.c:5: 警告:整數(shù)溢出
運行后:
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: 在函數(shù)‘main'中:
int_sizeof1.c:5: 警告:整數(shù)溢出
運行后:
The max value of int on 32 machine: 2147483647
VC6.0和java編譯后,無錯誤。
運行后:
The max value of int on 32 machine: 2147483647
因為int的最高位是符號位。
您可能感興趣的文章:
相關(guān)文章
C語言數(shù)據(jù)結(jié)構(gòu)之雙向循環(huán)鏈表的實例
這篇文章主要介紹了C語言數(shù)據(jù)結(jié)構(gòu)之雙向循環(huán)鏈表的實例的相關(guān)資料,需要的朋友可以參考下2017-06-06
C++下如何將TensorFlow模型封裝成DLL供C#調(diào)用
這篇文章主要介紹了C++下如何將TensorFlow模型封裝成DLL供C#調(diào)用問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-11-11
C++實現(xiàn)圖書管理系統(tǒng)課程設(shè)計(面向?qū)ο?
這篇文章主要為大家詳細介紹了C++實現(xiàn)圖書管理系統(tǒng)課程設(shè)計,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-03-03

