#include<stdio.h>
#include<iostream>
#include<queue>
#include<map>
#include<memory.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <climits>
#include <sstream>
#include <cstdlib>
using namespace std; /**
* 命名空间
*
*namespace identifier
*{
* named_entities
*}
*/
namespace foo
{
int value()
{
return 5;
}
} namespace bar
{
const double pi = 3.1416;
double value()
{
return 2 * pi;
}
} namespace first
{
int x = 5;
int y = 10;
} namespace second
{
double x = 3.1416;
double y = 2.7183;
} //int main()
//{
// cout << foo::value() << '\n';
// cout << bar::value() << '\n';
// cout << bar::pi << '\n';
// using first::x;
// using second::y;
// cout << x << endl;
// cout << y << endl;
// cout << first::y << endl;
// cout << second::x << endl;
// return 0;
//}
int x;
int main()
{
//using namespace和using的作用域
/*
{
using namespace first;
cout << x << '\n';
}
{
using namespace second;
cout << x << '\n';
}
//命名空间别名namespace new_name = current_name;
*/
//静态存储和自动存储
int y;
cout << x << '\n';
cout << y << '\n';
return 0;
}
/**
*
* The storage for variables with global or namespace scope is allocated for the entire duration of the program. This is known as static storage, and it contrasts with the storage for local variables (those declared within a block). These use what is known as automatic storage. The storage for local variables is only available during the block in which they are declared; after that, that same storage may be used for a local variable of some other function, or used otherwise.
*
*But there is another substantial difference between variables with static storage and variables with automatic storage:
*- Variables with static storage (such as global variables) that are not explicitly initialized are automatically initialized to zeroes.
*- Variables with automatic storage (such as local variables) that are not explicitly initialized are left uninitialized, and thus have an undetermined value.
*
*全局变量和命名空间是静态存储,在程序运行期间一直存在,本地变量是自动存储类型,只存在块内.
*
*俩个的不同点,静态存储的变量未初始化则默认值是0,自动存储变量值未初始化值是未确定
*
*/

  

c++官方文档-命名空间的更多相关文章

  1. clang format 官方文档自定义参数介绍(中英文)

    官方文档:http://clang.llvm.org/docs/ClangFormatStyleOptions.html 中文 在代码中配置样式 当使用 clang::format::reformat ...

  2. Spring JMS 官方文档学习

    最后部分的XML懒得写了,因为个人更倾向于JavaConfig形式. 为知笔记版本见这里,带格式~ 做了一个小demo,放到码云上了,有兴趣的点我. 说明:需要先了解下JMS的基础知识. 1.介绍 S ...

  3. Spring 4 官方文档学习(十一)Web MVC 框架

    介绍Spring Web MVC 框架 Spring Web MVC的特性 其他MVC实现的可插拔性 DispatcherServlet 在WebApplicationContext中的特殊的bean ...

  4. 【Docker官方文档】理解Docker

    本文来自Docker的官方文档,详细介绍了Docker的体系结构.重要概念.内部工作机理等内容,推荐不了解Docker内部原理的同学阅读. 什么是Docker? Docker是一个用于开发.交付和运行 ...

  5. gRPC官方文档(概览)

    文章来自gRPC 官方文档中文版 概览 开始 欢迎进入 gRPC 的开发文档,gRPC 一开始由 google 开发,是一款语言中立.平台中立.开源的远程过程调用(RPC)系统. 本文档通过快速概述和 ...

  6. 2017.4.10 spring-ldap官方文档学习

    官网:http://www.springframework.org/ldap 官方文档及例子(重要):http://docs.spring.io/spring-ldap/docs/2.1.0.RELE ...

  7. Protocol Buffers官方文档(proto3语言指南)

    本文是对官方文档的翻译,大部分内容都是引用其他一些作者的优质翻译使文章内容更加通俗易懂(自己是直译,读起来有点绕口难理解,本人英文水平有限),参考的文章链接在文章末尾 这篇指南描述如何使用protoc ...

  8. Hive官方文档

    Hive官方文档     内容列表 Cloudera制作的Hive介绍视频 安装与配置 系统需求 安装Hive发行版 从Hive源码编译 运行Hive 配置管理概览 运行时配置 Hive, Map-R ...

  9. 20191127 Spring Boot官方文档学习(9.1-9.3)

    9."使用方法"指南 9.1.Spring Boot应用程序 9.1.1.创建自己的FailureAnalyzer FailureAnalyzer被包装在FailureAnalys ...

随机推荐

  1. POJ 2312:Battle City(BFS)

    Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9885   Accepted: 3285 Descr ...

  2. 51Nod 1090: 3个数和为0

    1090 3个数和为0  基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 给出一个长度为N的无序数组,数组中的元素为整数,有正有负包括0,并互不相等. ...

  3. 只需 5 秒钟,你就能取到 WPF 程序的超高分辨率超高清截图

    我想要截取一个 WPF 程序的图标,但是它太小了.如果我就这样截屏截下来,是很不高清的.由于我需要制作一份课件,所以我需要超高清版本,可是,如何做才能最快速拿到 WPF 程序的超高清截图呢? 本文分享 ...

  4. 【转】python mysql数据库 'latin-1' codec can't encode character错误问题解决

    UnicodeEncodeError: 'latin-1' codec can't encode character   "UnicodeEncodeError:'latin-1' code ...

  5. dns over https 简单测试(docker 运行)

      dns over https 已经成为了标准了,给予我们的dns 解析添加了安全的支持 测试项目使用docker && docker-compose 运行 一张参考图 环境准备 d ...

  6. tomcat源码阅读之容器(Container)

    一. 实现容器的接口是Container接口,Tomcat中共有四种类型的容器: 1.Engine:表示整个Catalina Servlet引擎: 2.Host:表示含有一个或者多个Context容器 ...

  7. chrome 45以上flash被拦截的一种可能解决方案

    chrome 45以上不自动播放"非必要"flash的一种可能解决方案chrome 45以上flash被拦截的一种可能解决方案 问题 1.chrome 45以上(包含45)版本默认 ...

  8. 安装EKL

    elasticsearch rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch   /etc/yum.repos.d/ela ...

  9. C# ObjectArx AutoCAD二次开发(转帖)

    http://www.cnblogs.com/houlinbo/p/3325898.html 1.开发基本资料准备 用Vs2010进行Autocad 2010开发,首先下载ObjectArx 2010 ...

  10. css学习日记

    相对偏移 指定left top等属性就能够够完美控制一个元素的位置 如: position:relative; left:2px; 今天遇到一个很好玩的问题,当两个并排浮动框,当一个框的长度太大时就会 ...