C 语言实例 - 计算 int, float, double 和 char 字节大小
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 字节大小的更多相关文章
- C 语言实例 - 计算标准偏差
C 语言实例 - 计算标准偏差 计算标准偏差. 实例 #include <stdio.h> #include <math.h> float calculateSD(float ...
- C 语言实例 - 计算一个数的 n 次方
C 语言实例 - 计算一个数的 n 次方 计算一个数的 n 次方,例如: ,其中 为基数, 为指数. 实例 - 使用 while #include <stdio.h> int main() ...
- C 语言实例 - 计算平均值
C 语言实例 - 计算平均值 C 语言实例 C 语言实例 使用数组来计算几个数的平均值. 实例 #include <stdio.h> int main() { int n, i; ], s ...
- C 语言实例 - 计算自然数的和
C 语言实例 - 计算自然数的和 自然数是指表示物体个数的数,即由0开始,,,,,,……一个接一个,组成一个无穷的集体,即指非负整数. 实例 - 使用 for #include <stdio.h ...
- C 语言实例 - 计算两个时间段的差值
C 语言实例 - 计算两个时间段的差值 C 语言实例 C 语言实例 计算两个时间段的差值. 实例 #include <stdio.h> struct TIME { int seconds; ...
- C 语言实例 - 计算字符串长度
C 语言实例 - 计算字符串长度 C 语言实例 C 语言实例 计算字符串长度. 实例 - 使用 strlen() #include <stdio.h> #include <strin ...
- 关于c中 int, float, double转换中存在的精度损失问题
先看一段代码实验: #include<limits> #include<iostream> using namespace std; int main() { unsigned ...
- C++中将string类型转换为int, float, double类型 主要通过以下几种方式:
C++中将string类型转换为int, float, double类型 主要通过以下几种方式: # 方法一: 使用stringstream stringstream在int或float类型转换为 ...
- QT中QString 与 int float double 等类型的相互转换
Qt中 int ,float ,double转换为QString 有两种方法 1.使用 QString::number(); 如: long a = 63; QString s = QString:: ...
随机推荐
- A桶中有多少水?
如果你能算出桶中有多少水,我便许你下山去玩.有一天,老和尚让小和尚将A桶的水挑到B桶去,可是小和尚却想下山玩,不愿意挑水,老和尚便说:”如果你能够根据我的提示算出A桶中有多少升水,我便许你下山去玩.” ...
- ABAP读取工单状态 STATUS_READ
*&---------------------------------------------------------------------* *& Report YDEMO_013 ...
- 录音-树莓派USB摄像头话筒
实测可用: sudo arecord --duration=10 --device=plughw:1,0 --format=cd aaa.wav sudo arecord --duration=10 ...
- ./autogen.sh: 4: autoreconf: not found
./autogen.sh: 4: autoreconf: not found 是在不同版本的 tslib 下执行 autogen.sh 产生.它们产生的原因一样,是因为没有安装 automake ...
- UOJ Easy Round#7
UOJ Easy Round#7 传送门:http://uoj.ac/contest/35 题解:http://matthew99.blog.uoj.ac/blog/2085 #1 题意: 在一个(2 ...
- vue中引入百度统计
vue作为单页面的,引入百度统计,需要注意不少. 一.基本的流量统计 在index.html 入口文件中引入百度统计生成的一连串代码: var _hmt = _hmt || []; (function ...
- 棋盘覆盖问题 (粉书 P230 【递归】** )
转载自:http://blog.csdn.net/akof1314/article/details/5423608 (赞) 在一个 2^k * 2^k 个方格组成的棋盘中,若恰有一个方格与其它方格不 ...
- APP测试走过的那些坑
我现在的工作有一大部分也是app测试,虽然自己是app开发出身,但是在测试上还是跌入了很多大坑,毕竟二者还是有很大不同,所处的角度也是不一样的.而开发转测试中,我认为较难的也是一个角度的转换,以一个开 ...
- iPhone HTTP获得XML并使用GDataXML解析
1. [代码][C/C++]代码 NSURL *url = [NSURL URLWithString: @"http://www.raywenderlich.com/downloa ...
- React.js 之hello word
引入的js文件说明 react.js 是 React 的核心库 react-dom.js 是提供与 DOM 相关的功能 babel.min.js的作用是将 JSX 语法转为 JavaScript 语法 ...