我寫了下面的程序,它似乎對我需要做的事很好。但是,我不知道爲什麼UINT_MAX是給我-1輸出(通過的printf()),而不是4294967295,如下規定:https://www.tutorialspoint.com/c_standard_library/limits_h.htm爲什麼UINT_MAX返回-1?
#include <stdio.h>
#include <limits.h>
int main() {
printf("Below is the storage size for various data types.\n\n");
//char data type
printf("**char**\nStorage size: %d byte \t Minimum value: %d \t Maximum value: %d\n\n", sizeof(char), CHAR_MIN, CHAR_MAX);
//signed char data type
printf("**signed char**\nStorage size: %d byte \t Minimum value: %d \t Maximum value: %d\n\n", sizeof(signed char), SCHAR_MIN, SCHAR_MAX);
//unsigned char data type
printf("**unsigned char**\nStorage size: %d byte \t Maximum value: %d\n\n", sizeof(unsigned char), UCHAR_MAX);
//int data type
printf("**int**\nStorage size: %d bytes \t Minimum value: %d \t Maximum value: %d\n\n", sizeof(int), INT_MIN, INT_MAX);
//unsigned int data type
printf("**unsigned int**\nStorage size: %d bytes \t Maximum value: %d\n\n", sizeof(unsigned int), UINT_MAX);
}
難道我省略了細節或誤解的東西?
使用'%zu'代替'size_t'('sizeof'的結果)和'%u'代替'unsigned int' – BLUEPIXY