不同整型数据类型在内存中占多大

关于siazeof(a)、strlen(a)、a.length()、a.size()

https://blog.csdn.net/dujuancao11/article/details/104884030 

sizeof()返回一个对象或者类型所占的内存字节数(获取内存空间的大小)

适用范围:(1)字符串(2)字符、整型等各种数组,(3)int、flooat类型占的字节数记住头文件是cstring,string不可以

题目:

题目描述

确定不同整型数据类型在内存中占多大(字节),输出不同整型数据类型在内存中占多大(字节)。 

输入描述:

输出描述:

不同整型数据类型在内存中占多大(字节),具体格式详见输出样例,输出样例中的?为不同整型数据类型在内存中占的字节数。输出样例如下:
The size of short is ? bytes.
The size of int is ? bytes.
The size of long is ? bytes.
The size of long long is ? bytes.
#include<bits/stdc++.h>
using namespace std;
int main(){
	cout<<"The size of short is "<<sizeof(short)<<" bytes."<<endl;
	cout<<"The size of int is "<<sizeof(int)<<" bytes."<<endl;
	cout<<"The size of long is "<<sizeof(long)<<" bytes."<<endl;
	cout<<"The size of long long is "<<sizeof(long long)<<" bytes."<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/dujuancao11/article/details/108296397