1. 程式人生 > >C語言中各種整型型別所佔位元組數

C語言中各種整型型別所佔位元組數

平臺: 64位編譯器+LINUX+Gcc

 #include<stdio.h>
   main()
  {
     char a;
     char* b;
     short int c;
     int d;
     unsigned int e;
     float f;
    double g;
    long h;
    long long i;
    unsigned long j;
          
    printf("char a=%d\n",(int)sizeof(a));
    printf("char*b=%d\n",(int)sizeof(b));
    printf("short int c=%d\n",(int)sizeof(c));
    printf("int d=%d\n",(int)sizeof(d));
    printf("unsigned int e=%d\n",(int)sizeof(e));
    printf("float f=%d\n",(int)sizeof(f));
    printf("double g=%d\n",(int)sizeof(g));
    printf("long h=%d\n",(int)sizeof(h));
    printf("long long i=%d\n",(int)sizeof(i));
    printf("unsiged long j=%d\n",(int)sizeof(j));
  }


結果:

char a=1
char*b=8
short int c=2
int d=4
unsigned int e=4
float f=4
double g=8
long h=8
long long i=8
unsiged long j=8


 其它編譯器時的情況:

 16位編譯器

char :1個位元組  

  char*(即指標變數): 2個位元組 

  short int : 2個位元組 

  int: 2個位元組

  unsigned int : 2個位元組

  float: 4個位元組

  double: 8個位元組

  long: 4個位元組

  long long: 8個位元組

  unsigned long: 4個位元組

32位編譯器

  char :1個位元組

  char*: 4個位元組

  short    int : 2個位元組

   int: 4個位元組

   unsigned int : 4個位元組

   float: 4個位元組

   double: 8個位元組

    long: 4個位元組

long long: 8個位元組

    unsigned long: 4個位元組