CC++基本データ型バイト数

1223 ワード

CC++基本データ型バイト数
1バイト=8ビット
1 k=1024バイト=2^10
C言語型データのバイト数はマシンワード長やコンパイラと関係があり、int,long int,short intの幅はコンパイラによって異なる場合があります.しかし、いくつかの鉄の原則があります(ANSI/ISOが制定しました):
  • sizeof(short int)<=sizeof(int)
  • sizeof(int)<=sizeof(long int)
  • short intは少なくとも16ビット(2 Byte)
  • であるべきである.
  • long intは少なくとも32ビットであるべきである.

  • を選択します.
    32ビットコンパイラ
    64ビットコンパイラ
    char
    1 Byte
    1 Byte
    char*(ポインタ変数)
    4 Byte(32bit=4Byte)
    8 Byte
    short int
    2 Byte
    2 Byte
    int
    4 Byte
    4 Byte
    unsigned int
    4 Byte
    4 Byte
    float
    4 Byte
    4 Byte
    double
    8 Byte
    8 Byte
    long
    4 Byte
    8 Byte
    long long
    8 Byte
    8 Byte
    unsigned long
    4 Byte
    8 Byte
    検証方法:printf("%d",sizeof(char))各データ型の値範囲(ヘッダファイルに含まれる)を決定します.(char)((unsigned char) ~0 >>1)はsignedタイプ文字の最大値です.-(char)((unsigned char) ~0 >>1)はsignedタイプ文字の最小値です.
  • ~0//各バイナリビットはすべて1
  • に変換
  • (unsigned char)~0//結果unsigned charタイプ
  • に変換
  • (unsigned char)~0>>1//右シフト1ビットクリアシンボルビット
  • (char)((unsigned char)~0>>1)/signedタイプの最大値を取得し、charを置き換えて他のタイプの値範囲を取得します.