C语言基本数据类型大小

C语言基本数据类型占用的字节数可以通过如下例子获取:

#include<stdio.h>

int  main(void)
{
    printf("char size=%d 
",sizeof(char));
    printf("int size=%d 
",sizeof(int));
    printf("long size=%d 
",sizeof(long));
    printf("float size=%d 
",sizeof(float));
    printf("double size=%d 
",sizeof(double));
    printf("char* size=%d 
",sizeof(char*));
    printf("int* size=%d 
",sizeof(int*));
    printf("long* size=%d 
",sizeof(long*));
    printf("float* size=%d 
",sizeof(float*));
    printf("double* size=%d 
",sizeof(double*));
    printf("char[] size=%d 
",sizeof(char[2]));
    return 0;
}

执行结果:

$ ./size.exe
char size=1
int size=4
long size=8
float size=4
double size=8
char* size=8
int* size=8
long* size=8
float* size=8
double* size=8
char[] size=2

以上,单位是字节,一个字节为8比特

其中需要注意的是任何类型的指针变量占用8个字节

原文地址:https://www.cnblogs.com/jason207489550/p/6663478.html