[置顶] sizeof()和c++中变量们

sizeof()就像一个管家,知道家里的所有姑娘的身材一样,会为它们量身订做衣服,好让他们变得更加美丽动人,


// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{                                                 // 右侧为结果
cout<<"char"<<sizeof(char)<<endl;      // 1
cout<<"unsigned char"<<sizeof(unsigned char)<<endl;  //1
cout<<"signed char"<<sizeof(signed char)<<endl; //1
cout<<"int "<<sizeof(int)<<endl; //4
cout<<"unsigned int "<<sizeof(unsigned int )<<endl;//4
cout<<"signed int "<<sizeof(signed int)<<endl;      //4
cout<<"short int "<<sizeof(short int)<<endl; //2
cout<<"long int"<<sizeof(long int )<<endl;     //4  
cout<<"double"<<sizeof(double)<<endl; //8
cout<<"float"<<sizeof(float)<<endl;   //4
cout<<"string"<<sizeof(string)<<endl; //28
//_sleep(20);
cout<<endl;

int w;
cin>>w;
return 0;
}
[置顶] sizeof()和c++中变量们

从结果当中我们可以知道:

char 类型占 1个字节

unsigned char 类型占1个字节

signed char 类型占一个1字节

int  类型占4个字节

signed int 占 4个字节

unsigned int 类型占4个字节

short int 类型占2个字节

long int 类型占4个字节

double 类型占8个字节

float 类型占4个字节

string 类型张28个字节



原文链接: https://www.cnblogs.com/wsq724439564/archive/2013/04/12/3258193.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    [置顶] sizeof()和c++中变量们

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/84224

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 下午9:28
下一篇 2023年2月9日 下午9:28

相关推荐