zhangdemingQ

使用 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\n",sizeof(integerType));
    printf("Size of float: %ld bytes\n",sizeof(floatType));
    printf("Size of double: %ld bytes\n",sizeof(doubleType));
    printf("Size of char: %ld byte\n",sizeof(charType));
    return 0;
}

 

 

计算 long long, long double 字节大小

#include <stdio.h>
int main()
{
     int a;
     long b;
     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;
}

分类:

技术点:

相关文章:

  • 2021-11-13
  • 2021-12-15
  • 2021-12-04
  • 2021-12-15
  • 2021-12-29
猜你喜欢
  • 2021-10-16
  • 2021-12-29
  • 2021-12-14
  • 2021-12-29
  • 2021-11-30
相关资源
相似解决方案