zoukankan      html  css  js  c++  java
  • C 语言实例

    C 语言实例 - 计算 int, float, doublechar 字节大小
    
    C 语言实例 C 语言实例
    
    使用 sizeof 操作符计算int, float, double 和 char四种变量字节大小。
    sizeof 是 C 语言的一种单目操作符,如C语言的其他操作符++、--等,它并不是函数。
    sizeof 操作符以字节形式给出了其操作数的存储大小。
    实例
    #include <stdio.h>
     
    int main()
    {
        int integerType;
        float floatType;
        double doubleType;
        char charType;
     
        // sizeof 操作符用于计算变量的字节大小
        printf("Size of int: %ld bytes
    ",sizeof(integerType));
        printf("Size of float: %ld bytes
    ",sizeof(floatType));
        printf("Size of double: %ld bytes
    ",sizeof(doubleType));
        printf("Size of char: %ld byte
    ",sizeof(charType));
     
        return 0;
    }
    运行结果:
    Size of int: 4 bytes
    Size of float: 4 bytes
    Size of double: 8 bytes
    Size of char: 1 byte
    计算 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 
    ", sizeof(a));
        printf("Size of long = %ld bytes
    ", sizeof(b));
        printf("Size of long long = %ld bytes
    ", sizeof(c));
     
        printf("Size of double = %ld bytes
    ", sizeof(e));
        printf("Size of long double = %ld bytes
    ", sizeof(f));
     
        return 0;
    }
    运行结果:
    Size of int = 4 bytes 
    Size of long = 8 bytes
    Size of long long = 8 bytes
    Size of double = 8 bytes
    Size of long double = 16 bytes
  • 相关阅读:
    进程与线程
    闭包
    form表单提交
    让图片在div盒子中水平垂直居中
    第一个shell脚本——修改配置文件
    Linux系统find命令的常用方法
    Linux使echo命令输出结果带颜色
    Linux面试题
    无人值守批量安装
    Linux系统PXE高效批量网络装机的配置
  • 原文地址:https://www.cnblogs.com/bytebee/p/8535623.html
Copyright © 2011-2022 走看看