C 语言中int, float, double 和 char 字节大小

C 语言中int, float, double 和 char 字节大小

  • 使用 sizeof 操作符计算int, float, double 和 char四种变量字节大小。

  • sizeof 是 C 语言的一种单目操作符,并不是函数。

  • sizeof 操作符以字节形式给出了其操作数的存储大小。

#include <stdio.h>
 
int main()
{
    int intx;
    float floatx;
    double doublex;
    char charx;
    // sizeof 操作符用于计算变量的字节大小
    printf("Size of int: %ld bytes\n",sizeof(intx));
    printf("Size of float: %ld bytes\n",sizeof(floatx));
    printf("Size of double: %ld bytes\n",sizeof(doublex));
    printf("Size of char: %ld byte\n",sizeof(charx));
 
    return 0;
}

在这里插入图片描述

计算 long long, long double 字节大小

#include <stdio.h>
int main()
{
    int a;
    long b;
    long long c;
 
    double e;
    long double f;
 
 
    printf("Size of int = %ld bytes \n", sizeof(a));
    printf("Size of long = %ld bytes\n", sizeof(b));
    printf("Size of long long = %ld bytes\n", sizeof(c));
 
    printf("Size of double = %ld bytes\n", sizeof(e));
    printf("Size of long double = %ld bytes\n", sizeof(f));
 
    return 0;
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值