zoukankan      html  css  js  c++  java
  • C++ 全局变量与局部变量

    /****Lession1.h****/

    extern bool a;
    extern int b;
    extern float c;
    extern double d;
    extern unsigned int e;
    extern long f;
    extern unsigned long g;
    extern char h;
    extern long double i;

    /****Lession1.cpp****/

    #include "stdafx.h"
    #include "Lession1.h"
    bool a;
    int b;
    float c;
    double d;
    unsigned int e;
    long f;
    unsigned long g;
    char h;
    long double i;

    /****Test.cpp****/

    #include "stdafx.h"
    #include <iostream>
    #include "Lession1.h"
    using namespace std;
    int _tmain(int argc, _TCHAR* argv[])
    {
    int b=2;
    ::a = true;
    ::b = 1;
    ::c = float();
    ::d = double();
    ::e = unsigned int();
    ::f = long();
    ::g = unsigned long();
    ::h = char();
    ::i = long double();
    cout<<"全局变量 b="<<::b<<endl;
    cout<<"局部变量 b="<<b<<endl;
    cout<<"bool 所占字节数:"<<sizeof(a)<<endl;
    cout<<"int 所占字节数:"<<sizeof(b)<<endl;
    cout<<"float 所占字节数:"<<sizeof(c)<<endl;
    cout<<"double 所占字节数:"<<sizeof(d)<<endl;
    cout<<"unsigned int 所占字节数:"<<sizeof(e)<<endl;
    cout<<"long 所占字节数:"<<sizeof(f)<<endl;
    cout<<"unsigned long 所占字节数:"<<sizeof(g)<<endl;
    cout<<"char 所占字节数:"<<sizeof(h)<<endl;
    cout<<"long double 所占字节数:"<<sizeof(i)<<endl;

    }


  • 相关阅读:
    深入浅出 JVM ClassLoader
    JVM 线上故障排查基本操作
    深入浅出 JVM GC(3)
    MyBatis 源码分析系列文章合集
    MyBatis 源码分析
    MyBatis 源码分析
    MyBatis 源码分析
    MyBatis 源码分析
    MyBatis 源码分析
    MyBatis 源码分析系列文章导读
  • 原文地址:https://www.cnblogs.com/handongdong/p/2223758.html
Copyright © 2011-2022 走看看