【C++】Data Type Size Of

这次我们要来学习资料型态在程式中的大小,亦即调查其所占的空间。

我列出一些常用的data type~ unsigned就先不放了lol~ 因为太複杂


学习目标: 资料型态大小的概念

学习难度: ☆☆☆


http://img2.58codes.com/2024/20147886MP4snT847V.png


#include <iostream>using namespace std;void DataTypeSize();int main() {DataTypeSize();}void DataTypeSize(){  char cha[] = "I am wei tsung";     char *p1=cha;     char **p2=&p1;    string name="wei tsung";    cout<<"cha[] size is "<<sizeof(cha)<<" bytes"<<"\n"<<endl; //15 bytes (null、阵列最后会有一个空个都算1byte)    cout<<"char *p1 size is "<<sizeof(*p1)<<" bytes"<<"\n"<<endl; //1 byte    cout<<"char **p2 size is "<<sizeof(**p2)<<" bytes"<<"\n"<<endl; //1 byte    cout<<"string name size is "<<sizeof(name)<<" bytes"<<"\n"<<endl;  //8 bytes     cout<<"short int size is "<<sizeof(short int)<<" bytes"<<"\n"<<endl; //2 bytes    cout<<"int size is "<<sizeof(int)<<" bytes"<<"\n"<<endl; //4 bytes    cout<<"long long int size is "<<sizeof(long long int)<<" bytes"<<"\n"<<endl; //8 bytes    cout<<"float size is "<<sizeof(float)<<" bytes"<<"\n"<<endl; //4 bytes  cout<<"double size is "<<sizeof(double)<<" bytes"<<"\n"<<endl; //8 bytes    cout<<"double size is "<<sizeof(longdouble)<<" bytes"<<"\n"<<endl; //12 bytes    cout<<"wchar_t size is "<<sizeof(wchar_t)<<" bytes"<<"\n"<<endl; //2 bytes}

参考资料:

https://www.geeksforgeeks.org/c-data-types/


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章