數(shù)據(jù)類型指定變量可以存儲的數(shù)據(jù)的類型,例如:整數(shù),浮點,字符等。
C語言中有4
種類型的數(shù)據(jù)類型。
類型 | 包含的類型 |
---|---|
基本數(shù)據(jù)類型(Basic Data Type) | int, char, float, double |
派生數(shù)據(jù)類型(Derived Data Type) | array, pointer, structure, union |
枚舉數(shù)據(jù)類型(Enumeration Data Type) | enum |
Void數(shù)據(jù)類型(void Data Type) | void |
基本數(shù)據(jù)類型是基于整數(shù)和基于浮點數(shù)。C語言支持有符號和無符號文字。
基本數(shù)據(jù)類型的內存大小可能會根據(jù)32位或64位操作系統(tǒng)而有所變化。
下面來看看看基本的數(shù)據(jù)類型,下面是根據(jù)32
位機器的架構給出的大小范圍。
數(shù)據(jù)類型 | 內存大小 | 范圍 |
---|---|---|
char | 1 byte | 1?128 to 127 |
signed char | 1 byte | ?128 to 127 |
unsigned char | 1 byte | 0 to 255 |
short | 2 byte | ?32,768 to 32,767 |
signed short | 2 byte | ?32,768 to 32,767 |
unsigned short | 2 byte | 0 to 65,535 |
int | 2 byte | ?32,768 to 32,767 |
signed int | 2 byte | ?32,768 to 32,767 |
unsigned int | 2 byte | 0 to 65,535 |
short int | 2 byte | ?32,768 to 32,767 |
signed short int | 2 byte | ?32,768 to 32,767 |
unsigned short int | 2 byte | 0 to 65,535 |
long int | 4 byte | -2,147,483,648 to 2,147,483,647 |
signed long int | 4 byte | -2,147,483,648 to 2,147,483,647 |
unsigned long int | 4 byte | 0 to 4,294,967,295 |
float | 4 byte | - |
double | 8 byte | - |
long double | 10 byte | - |