#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. Unity 3D游戏-贪吃蛇类游戏源码:重要方法和功能的实现

    贪吃蛇类游戏源码 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) 1 头部移动方式 2 生成 Shit 道具 ...

  2. 在 Windows 10 中开启移动 WLAN 热点

    本文将介绍如何在 Windows 10 中开启移动 Wi-Fi 热点. This post is written in multiple languages. Please select yours: ...

  3. java8 array、list操作 汇【2】)- (Function,Consumer,Predicate,Supplier)应用

    static class UserT { String name; public UserT(String zm) { this.name=zm; } public String getName() ...

  4. Microsoft - Union Two Sorted List with Distinct Value

    Union Two Sorted List with Distinct Value Given X = { 10, 12, 16, 20 } &  Y = {12, 18, 20, 22} W ...

  5. 在Spark上通过BulkLoad快速将海量数据导入到Hbase

    我们在<通过BulkLoad快速将海量数据导入到Hbase[Hadoop篇]>文中介绍了一种快速将海量数据导入Hbase的一种方法,而本文将介绍如何在Spark上使用Scala编写快速导入 ...

  6. hadoop 配置文件简析

    文件名称            格式                     描述 hadoop-env.sh      bash脚本            记录hadoop要用的环境变量 core- ...

  7. Python与机器学习

    pandas里面的对于数据操作比如where,drop以及dropna等都会有一个属性:inplace,这个单词意思是原地,如果inplace=true代表数据本身要返回(原地数据也会被改变):如果i ...

  8. FineUI中在一个页面中通过控件事件(JS)向父页面中添加Tab页

    1.在前台页面尾部添加js代码 </form>    <script type="text/javascript">        var basePath ...

  9. Microsoft Dynamics CRM2011 导入解决方案时,失败的原因小结

    将大的自定义文件导入到 Microsoft Dynamics CRM 时发生超时? 如图: 首先: a.首先需要确认两面的CRM 环境是一致,比如都是Roll up 11等. b.然后确认导出解决方案 ...

  10. react-native在mac上执行gradlew命令报错 ./gradlew: command not found

    这是因为react-native项目是windows上初始化,通过git clone到mac机器上后gradlew这个文件没有可执行权限,如图: 所以只需要给gradlew这个文件增加可执行权限就可以 ...