C++@语句块
2024-08-22 00:25:07
#include <iostream>
using namespace std; int main()
{
{
int x=1;
cout << x << endl;
{
cout << x << endl;
int x=2;
cout << x <<endl;
{
cout << x <<endl;
int x=3;
cout << x <<endl;
}
cout << x <<endl;
}
cout << x << endl;
}
return 0;
}
输出结果 1 1 2 2 3 2 1
#include <iostream>
using namespace std; int main()
{
{
int x1=1;
cout << x1 << endl;
{
cout << x1 << endl;
int x2=2;
cout << x2 <<endl;
{
cout << x2 <<endl;
int x3=3;
cout << x3 <<endl;
}
cout << x2 <<endl;
}
cout << x1 << endl;
}
return 0;
}
输出结果 1 1 2 2 3 2 1
/*
* 在第一例每个语句块中,虽然变量名都一样,但是int x= ;之后x就变成另外一个变量了
* 且生存周期仅限于当前的语句块中
*/
最新文章
- 【转】Python练习,网络爬虫框架Scrapy
- Maven打包跳过测试
- FMDB处理动态插入语句
- SimpleDateFormat出错
- Xcode 的正确打开方式——Debugging(转载)
- MVC神韵---你想在哪解脱!(十三)
- mysql与java数据类型对照
- JAVA对数据库进行操作,实现数据库中数据的插入,查询,更改,删除操作
- peoplesoft function PSTREENODE 通过 deptid 获得部门树 一级部门 名称
- 496. Next Greater Element I
- SQL Server 2016 行级别权限控制
- JQuery基础知识学习1
- 将nginx永久加入到系统环境变量
- Winscp使用sudo user登录
- See you~ HDU1892
- [LeetCode] 10. Regular Expression Matching ☆☆☆☆☆
- 丢弃昂贵的Detours Professional 3.0,使用免费强大的EasyHook
- docker发布spring cloud应用
- thinkphp控制器的使用
- render 的执行流程