当前位置:首页 > C++ > 正文内容

数据类型及其占用空间

chanra1n4年前 (2020-10-28)C++4171
#include<iostream>
using namespace std;
int main()
{
	cout << "The size of int is " <<sizeof(int) <<endl;
	cout << "The size of short is " <<sizeof(short) <<endl;
	cout << "The size of long is " <<sizeof(long) <<endl;
	cout << "The size of bool is " <<sizeof(bool) <<endl;
	cout << "The size of char is " <<sizeof(char) <<endl;
	cout << "The size of float is " <<sizeof(float) <<endl;
	cout << "The size of double is " <<sizeof(double) <<endl;
	return 0;
}

运行的结果是

The size of int is 4
The size of short is 2
The size of long is 4
The size of bool is 1
The size of char is 1
The size of float is 4
The size of double is 8

单位是字节

扫描二维码推送至手机访问。

版权声明:本文由我的FPGA发布,如需转载请注明出处。

本文链接:https://myfpga.cn/index.php/post/155.html

分享给朋友:

“数据类型及其占用空间” 的相关文章

C++ 中的变量类型创建和使用

C++ 中的变量类型创建和使用

      C++中需要掌握的只有int(整型)float (浮点)char (字符),其他的可自行百度后学习,但是基本上用不到      int float char 这三种类型,换成说人话的解释就是:   ...

一小时搞定C++_7

一小时搞定C++_7

假如我让你计算从1加到500,你会怎么计算,用累加公式?假如,没有累加公式,你只能从1挨个往上加,用计算机能不能实现这一一件事呢?4种方法:1、#include <iostream> using namespace std; int main(...

C++入门 输出Hello World

C++入门 输出Hello World

#include <iostream>using namespace std;int main(){     cout << "Hello, world!...

Break和Continue的区别

Break和Continue的区别

#include<iostream>  using namespace std; int main() { int x=0; for(x=0;x<10;x++) { if(x==3) break;...

C++ 数组的各类性质和用法

C++ 数组的各类性质和用法

#include<iostream>  using namespace std; void addarr(int *k,int len); //文中形如sizeof(x)/sizeof(x[0]) 是用数组占用空...