C 資料型別的大小

2021-07-05 21:18:16 字數 1347 閱讀 6418

一、c

1.幾條規則

(1)char型別一般是8bit,但ansi c裡沒有硬性規定其長度,某些嵌入式編譯器可能是16bit

(2)short和long型別的長度不相同

(3)int型別通常同具體機器的物理字長相同

(4)short通常是16bits, int通常是16bits or 32bits每種編譯器可以根據硬體的不同自由確定, 但是short和int必須最少是16bits, 而long型別必須最少是32bits, 並且short必須比int和long型別要短。

2.32位機上型別長度

size of char: 1

size of int: 4

size of long:4

size of float:4

size of long long:8

size of double:8

size of long double:12

size of char * :4

size of string:16//32位機下vc6.0編譯器下

3.64位機上型別長度

size of char:1

size of int:4

size of long :8

size of float :4

size of long long:8

size of double:8

size of long double:16

size of char * :8

size of bool:1

size of string:32//64位機vs2013編譯器下

4.16位機型別長度

char: 1

int: 2

long:4

unsigned int:2

unsigned short:2

unsigned long:4

float:4

size of char * :4

二、c++

1.位元組和字長

位元組,八位就是乙個位元組,是固定概念。字長是指計算機一次能處理的二進位制資料的長度,是乙個非固定的概念。例如,8位計算機的字長為8,即乙個位元組, 32位計算機的字長位32,即4個位元組,同理,64位計算機的字長為64,即8位元組。

2.char型別始終是乙個位元組長,即8位。

3.int、short int和long int

通常int為乙個字長,short為半個字長,long為乙個或2個字長(在32位機器中為乙個字長)。

4.浮點型float、雙精度double、和長雙精度long double

典型情況下,float 為乙個字,double是兩個字,long double為三個或四個字。

C 資料型別大小

iostream void main 輸出結果 size of bool 1 bytes size of char 1 bytes size of unsigned char 1 bytes size of wchar t 2 bytes size of short 2 bytes size of ...

C 資料型別所佔位元組大小

對於指標型別,因為指標指向的是乙個位址,32位作業系統就是4位元組。64位作業系統那就是8位元組了。int這個型別佔作業系統乙個記憶體單元大小。早先16位作業系統乙個記憶體單元是16位,所以是2個位元組 32位系統乙個記憶體單元是是32位,所以是4位元組 64位作業系統,4位元組。整形加unsign...

C中資料型別占用記憶體的大小

資料型別表示儲存何種型別的資料,從記憶體來看,就是占用的記憶體大小。c標準並未明確規定各資料型別占用多少位元組的儲存空間。各資料型別的記憶體大小與作業系統位數 編譯器有關,可以在 中使用sizeof 進行查詢。1 字元型別 char占用1個位元組 表示的是字元對應的ascii碼 2 浮點型別 flo...