zoukankan      html  css  js  c++  java
  • [置顶] 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;
    }


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

    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个字节



  • 相关阅读:
    学习Linux shell脚本中连接字符串的方法
    使用 ffmpeg 转换视频格式
    一点不懂到小白的linux系统运维经历分享
    linux利用scp远程上传下载文件/文件夹
    angular ui-select
    JavaScript sort()方法
    js性能优化
    layer弹出层
    JS复制对象
    某天修改了啥bat批处理
  • 原文地址:https://www.cnblogs.com/wsq724439564/p/3258193.html
Copyright © 2011-2022 走看看