c语言数据类型字节大小

C&C++ / 41人浏览 / 0人评论

c语言中,数据类型指的是用于声明不同类型的变量或函数;变量的类型决定了变量存储占用的空间。

c整数类型存储大小计算

#include <stdio.h>
#include <stdlib.h>

int main()
{

    printf("void 存储大小 :%d\n", sizeof(void));
    printf("char 存储大小 :%d\n", sizeof(char));
    printf("unsigned char 存储大小 :%d\n", sizeof(unsigned char));
    printf("short 存储大小 :%d\n", sizeof(short));
    printf("unsigned short 存储大小 :%d\n", sizeof(unsigned short));
    printf("int 存储大小 :%d\n", sizeof(int));
    printf("unsigned int 存储大小 :%d\n", sizeof(unsigned int));
    printf("long 存储大小 :%d\n", sizeof(long));
    printf("unsigned long 存储大小 :%d\n", sizeof(unsigned long));
    printf("float 存储大小 :%d\n", sizeof(float));
    printf("double 存储大小 :%d\n", sizeof(double));
    printf("long int 存储大小 :%d\n", sizeof(long int));
    printf("long long 存储大小 :%d\n", sizeof(long long));
    printf("long double 存储大小 :%d\n", sizeof(long double));
    return 0;
}

打印输出

void 存储大小 :1
char 存储大小 :1
unsigned char 存储大小 :1
short 存储大小 :2
unsigned short 存储大小 :2
int 存储大小 :4
unsigned int 存储大小 :4
long 存储大小 :4
unsigned long 存储大小 :4
float 存储大小 :4
double 存储大小 :8
long int 存储大小 :4
long long 存储大小 :8
long double 存储大小 :16

转载注明:

0 条评论

还没有人发表评论

发表评论 取消回复

记住我的信息,方便下次评论
有人回复时邮件通知我