C 语言实例 - 计算 int, float, double 和 char 字节大小

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\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 ;
}
运行结果:
Size of int: bytes
Size of float: bytes
Size of double: bytes
Size of char: 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 \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 ;
}
运行结果:
Size of int = bytes
Size of long = bytes
Size of long long = bytes
Size of double = bytes
Size of long double = bytes

C 语言实例 - 计算 int, float, double 和 char 字节大小的更多相关文章

  1. C 语言实例 - 计算标准偏差

    C 语言实例 - 计算标准偏差 计算标准偏差. 实例 #include <stdio.h> #include <math.h> float calculateSD(float ...

  2. C 语言实例 - 计算一个数的 n 次方

    C 语言实例 - 计算一个数的 n 次方 计算一个数的 n 次方,例如: ,其中 为基数, 为指数. 实例 - 使用 while #include <stdio.h> int main() ...

  3. C 语言实例 - 计算平均值

    C 语言实例 - 计算平均值 C 语言实例 C 语言实例 使用数组来计算几个数的平均值. 实例 #include <stdio.h> int main() { int n, i; ], s ...

  4. C 语言实例 - 计算自然数的和

    C 语言实例 - 计算自然数的和 自然数是指表示物体个数的数,即由0开始,,,,,,……一个接一个,组成一个无穷的集体,即指非负整数. 实例 - 使用 for #include <stdio.h ...

  5. C 语言实例 - 计算两个时间段的差值

    C 语言实例 - 计算两个时间段的差值 C 语言实例 C 语言实例 计算两个时间段的差值. 实例 #include <stdio.h> struct TIME { int seconds; ...

  6. C 语言实例 - 计算字符串长度

    C 语言实例 - 计算字符串长度 C 语言实例 C 语言实例 计算字符串长度. 实例 - 使用 strlen() #include <stdio.h> #include <strin ...

  7. 关于c中 int, float, double转换中存在的精度损失问题

    先看一段代码实验: #include<limits> #include<iostream> using namespace std; int main() { unsigned ...

  8. C++中将string类型转换为int, float, double类型 主要通过以下几种方式:

      C++中将string类型转换为int, float, double类型 主要通过以下几种方式: # 方法一: 使用stringstream stringstream在int或float类型转换为 ...

  9. QT中QString 与 int float double 等类型的相互转换

    Qt中 int ,float ,double转换为QString 有两种方法 1.使用 QString::number(); 如: long a = 63; QString s = QString:: ...

随机推荐

  1. it starts (“forks”) a new process for each connection.

    PostgreSQL: Documentation: 10: 1.2. Architectural Fundamentals https://www.postgresql.org/docs/10/st ...

  2. J++ C#

    J++几乎有与Java相同的编程语言和虚拟机.

  3. android DownloadManager.getInputStream返回null的一种情况

    将下载操作的代码放到一个新的子线程中来执行.

  4. const与define应用上该怎么取舍

    const与define应用上该怎么取舍 #define WYB 100; const float WYB = 100; define是在预编译的时候展开替换的,const是编译运行阶段使用 defi ...

  5. BluetoothLELibrary 支持1对1连接

    github地址:https://github.com/qindachang/BluetoothLELibrary 该库只支持1对1连接,如果你想1对多设备连接,请移步至 BluetoothLE-Mu ...

  6. 自然语言处理:问答 + CNN 笔记

    参考 Applying Deep Learning To Answer Selection: A Study And An Open Task follow: http://www.52nlp.cn/ ...

  7. BZOJ2120:数颜色(数状数组套主席树)(带修改的莫对)

    墨墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成一排,你需要回答墨墨的提问.墨墨会像你发布如下指令: 1. Q L R代表询问你从第L支画笔到第R支画笔中共有几种不同颜色的画笔. 2. R P ...

  8. ubuntu bcompare 安装

    Terminal Install wget http://www.scootersoftware.com/bcompare-4.2.8.23479_amd64.deb sudo apt-get upd ...

  9. weex 安装过程中遇到的坑

    安装 然后 注意: 在weex-toolkit1.0.8版本后添加了npm5规范的npm-shrinkwrap.json用于锁定包依赖,故npm版本<5的用户需要通过npm i npm@late ...

  10. SecureCRT rz上传文件失败

    SecureCRT 将 Windows 上的文件传至 Linux 端,小的文件没有问题能够正常上传,但是对于几百M的文件往往上传过程中失败. 解决办法:使用 rz -be,并且去掉对话框中" ...