200512030724C++數值型別解釋
C++ 預先定義了一組數值型別,可用來表示整數、浮點數、字元。
- 型別char 通來用來表示個別字元和小型整數,大小為一個 machine byte。
- 型別 short、int與long 表示數值。short大小通常代表半個machine word;int大小表示成一個machine word;long可能是一個或兩個machine word(在32bit機器上,int與long通常有相同的大小)。
- 型別float、double、long double 代表浮點數的單精度、倍精度、擴充精度。float大小表示成一個machine word;double大小為兩個machine word;long double大小以三個或四個machine word表示。
char、short、int和long,統稱為整數型別。整數型別可以有正 負號(signed),也可以無正負號(unsigned);整數型別預設為有正負號整數型別。浮點數統統有正負號。例如: (signed)char 數值範圍-127~128,unsigned char數值範圍-0~255。
數值型別表示數值的範圍可以由#include<limits>的numeric_limits表示之。
char:
cout<<(int)numeric_limits
cout<<(int)numeric_limits
int:
cout<
cout<numeric_limits<int>
其他的數值型別以此類推。
回應