前沿拓展:64位的短整形多少個字節(jié)

哎,老大們居然沒有一個說完整的,或者就是有筆誤的。

大體上套用貝式弧現(xiàn)的答案吧,糾正一下他的幾處錯誤:

在標(biāo)準(zhǔn)C++中的來自int的字節(jié)長度術(shù)每云小于long大于short就行了,多數(shù)平臺上int占4個字節(jié)(32位,不是16位?。?,所以能表示的范圍就是2的32次方,表李歷希建士端開話根同先示為數(shù)值是-2^(32-1) ~ 2^(32-1) -1 ( ^ 表示成方 )(就是 -2^31 ~ 2^31 - 1, 而不是2^16...)
訴笑皇深章蘇察傳頭據(jù)不同的需要,int包括以下定義:
unsigned short int 得責(zé)武至松無符號2字節(jié)短整形
short int 帶符號2字節(jié)短整形 - 32768 ~ 32767
unsigned int 響溶會帶每仍教皇無符號4字節(jié)整形 0 ~ 2^32 -1 (這個是對的)
int 4字節(jié)整形 - 2^31 ~ 2^31 - 1
int 64 6附排界貴胞世矛相依席4位(8字節(jié))整形 - 2系^63 ~ 2^63 - 1 (這個很少用到,一般是表示為高位int和低位int,貝式弧現(xiàn)對它的范圍也給錯了)

用C語言測試自己編譯器所占字節(jié)的大小,代碼實現(xiàn)如下:

#include<stdio.h>

#include<climits>

#include<float.h>

int main()

{

int* p;

printf("char = %d\n", sizeof(char));

printf("signed char = %d\n", sizeof(signed char));

printf("unsigned char = %d\n", sizeof(unsigned char));

printf("short = %d\n", sizeof(short));

printf("signed short = %d\n", sizeof(signed short));

printf("unsigned short = %d\n", sizeof(unsigned short));

printf("int = %d\n", sizeof(int));

printf("signed int = %d\n", sizeof(signed int));

printf("unsinged int = %d\n", sizeof(unsigned int));

printf("float = %d\n", sizeof(float));

printf("double = %d\n", sizeof(double));

printf("long = %d\n", sizeof(long));

printf("signed long = %d\n", sizeof(signed long));

printf("unsigned long = %d\n", sizeof(unsigned long));

printf("longlong = %d\n", sizeof(LONGLONG));

printf("p = %d\n", sizeof(p));

return 0;

}

1234567891011121314151617181920212223242526272829303132

運行結(jié)果如下:

再來看一下每個關(guān)鍵字的大值

#include<iostream>

#include<climits>

using namespace std;

int main()

{

char n_char = CHAR_MAX;

char n_schar = SCHAR_MAX;

char n_uchar = UCHAR_MAX;

short n_short = SHRT_MAX;

short n_ushort = USHRT_MAX;

int n_int = INT_MAX;

unsigned int n_uint = UINT_MAX;

float n_float = FLT_MAX;

float n_maxfloat = FLT_MANT_DIG;

float n_10float = FLT_MAX_10_EXP;

long n_long = LONG_MAX;

long n_Ulong = ULONG_MAX;

long long n_llong = LLONG_MAX;

long long n_ullong = ULLONG_MAX;

cout << "max value is :" << endl;

cout << "char is:" << n_char << endl;

cout << "usigned char is:" << n_schar << endl;

cout << "unsigned char is:" << n_uchar << endl;

cout << "int is:" << n_int << endl;

cout << "unsigned int is:" << n_uint << endl;

cout << "short is:" << n_short << endl;

cout << "unsigned short is:" << n_ushort << endl;

cout << "folat is :" << n_float << endl;

cout << "numbers of float is:" << n_maxfloat << endl;

cout << "float 10_exp is:" << n_10float << endl;

cout << "long is:" << n_long << endl;

cout << "unsigned long is:" << n_Ulong << endl;

cout << "long long is:" << n_llong << endl;

cout << "unsigned long long is:" << n_ullong << endl;

return 0;

}

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051

運行結(jié)果:

因為char沒有大值,所以這里沒有輸出結(jié)果!

每個關(guān)鍵字的小值

#include<iostream>

#include<climits>

using namespace std;

int main()

{

short n_short = SHRT_MIN;

int n_int = INT_MIN;

float n_float = FLT_MIN;

float n_10float = FLT_MIN_10_EXP;

long n_long = LONG_MIN;

long long n_llong = LLONG_MIN;

cout << "min value is :" << endl;

cout << "int is:" << n_int << endl;

cout << "short is:" << n_short << endl;

cout << "folat is :" << n_float << endl;

cout << "float 10_exp is:" << n_10float << endl;

cout << "long is:" << n_long << endl;

cout << "long long is:" << n_llong << endl;

return 0;

}

12345678910111213141516171819202122232425262728293031323334

運行結(jié)果:

有關(guān)每一個字節(jié)的取值范圍如下: 1、char:表示字符型數(shù)據(jù),占1個字節(jié)(8個二進(jìn)制位),包含256個不同的整數(shù)。 有符號的范圍: -128 ~ 127。每個整數(shù)都對應(yīng)一個字符。整數(shù)和字符的對應(yīng)關(guān)系由ASCII碼表規(guī)定。 無符號的范圍:0 ~ 255。1234

2、short:表示短整型數(shù)據(jù),一般占2個字節(jié)(16個二進(jìn)制位)。

有符號的范圍:-32768 ~ 32767。

無符號的范圍0到65535。

1234

3、int:表示基本整型數(shù)據(jù),一般占4個字節(jié)(32個二進(jìn)制位)。

有符號的范圍:-2147483648 ~ 2147483647。

無符號的范圍:0 ~ 4294967295。

1234

4、long:表示長整型數(shù)據(jù),一般占4個字節(jié)(32個二進(jìn)制位)。

有符號的范圍:-2147483648 ~ 2147483647。

無符號的范圍:0 ~ 4294967295。

1234

5、float:表示單精度浮點型數(shù)據(jù),一般占4個字節(jié)(32個二進(jìn)制位,1bit(符號位) 8bits(指數(shù)位) 23bits(尾數(shù)位))。

范圍:-3.40E+38 ~ +3.40E+38

精度:6 ~ 7位有效數(shù)字

1234

6、double:表示雙精度浮點型數(shù)據(jù),一般占8個字節(jié)(64個二進(jìn)制位,1bit(符號位) 11bits(指數(shù)位) 52bits(尾數(shù)位))。

范圍:-1.79E+308 ~ +1.79E+308

精度:15 ~ 16位有效數(shù)字

1234

7、unsigned:表示無符號數(shù)據(jù)。

8、signed:表示有符號數(shù)據(jù),默認(rèn)不用寫。

另外,我將不同位平臺下關(guān)鍵字所占的字節(jié)的鏈接貼在下面: https://blog.csdn.net/cherrydreamsover/article/details/81022994

拓展知識:64位的短整形多少個字節(jié)

還有其他疑惑?想了解更多?可以點擊 【在線咨詢】