求32位機器上unsigned int的最大值及int的最大值的解決方法
更新時間:2013年05月31日 17:35:45 作者:
本篇文章是對求32位機器上unsigned int的最大值及int的最大值的解決方法進行了詳細的分析介紹,需要的朋友參考下
復(fù)制代碼 代碼如下:
#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);
}
復(fù)制代碼 代碼如下:
#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
復(fù)制代碼 代碼如下:
#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寫成有符號型的程序如下:
復(fù)制代碼 代碼如下:
#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)算法之實現(xiàn)快速傅立葉變換
這篇文章主要介紹了C語言數(shù)據(jù)結(jié)構(gòu)算法之實現(xiàn)快速傅立葉變換的相關(guān)資料,需要的朋友可以參考下2017-06-06
Qt中QMapIterator檢測是否為空的實現(xiàn)
本文主要介紹了Qt中QMapIterator檢測是否為空的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-10-10
C語言錯誤信息報告strerror函數(shù)和perror函數(shù)詳解
這篇文章主要介紹了C語言錯誤信息報告strerror函數(shù)和perror函數(shù),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-03-03

