1. 程式人生 > >C語言中關鍵字所佔用位元組大小

C語言中關鍵字所佔用位元組大小

#include <stdio.h>

void main(){
    /*int 位元組*/
    printf("%d\n",sizeof(int)); //4 
    printf("%d\n",sizeof(__int8)); //1
    printf("%d\n",sizeof(__int16)); //2
    printf("%d\n",sizeof(__int32)); //4
    printf("%d\n",sizeof(__int64)); //8
    /*char 位元組*/
    printf("%d\n",sizeof(char)); //1
    /*double 位元組*/
    printf("%d\n",sizeof(double)); //8
    /*long 位元組*/
    printf("%d\n",sizeof(long)); //4
    printf("%d\n",sizeof(long int)); //4
    printf("%d\n",sizeof(long long)); //8
    /*short 位元組*/
    printf("%d\n",sizeof(short)); //2 
    printf("%d\n",sizeof(short int)); //2
    /*unsigned 位元組*/
    printf("%d\n",sizeof(unsigned)); //4
    printf("%d\n",sizeof(unsigned int)); //4
    printf("%d\n",sizeof(unsigned __int64)); //8
    printf("%d\n",sizeof(unsigned __int32)); //4
    printf("%d\n",sizeof(unsigned __int16)); //2
    printf("%d\n",sizeof(unsigned __int8)); //1
    /*signed 位元組*/
    printf("%d\n",sizeof(signed)); //4
    printf("%d\n",sizeof(signed int)); //4
    printf("%d\n",sizeof(signed __int64)); //8
    printf("%d\n",sizeof(signed __int32)); //4
    printf("%d\n",sizeof(signed __int16)); //2
    printf("%d\n",sizeof(signed __int8)); //1
    /*const 位元組*/
    printf("%d\n",sizeof(const)); //4
    /*結構體 位元組*/
    typedef struct
    {
        unsigned short eeRelatedID;
        unsigned char check[2];
    }eeRelatedIDType;
    printf("%d\n",sizeof(eeRelatedIDType)); //4
    /*列舉 位元組*/ 
    enum Day{
        MON=1,TUE,WED,THU,FRT,SAT,SUN
    };
    enum Day today;
    printf("%d\n",sizeof(today));//4 
    /*共用體 位元組*/
    union Data{
        int n; //4
        char ch;
        short m;
    };
    union Data a;
    printf("%d\n",sizeof(a)); //4