当前位置:网站首页>2. Variables and scope
2. Variables and scope
2022-07-29 03:38:00 【Timindream】
1. Variable
Use and define , And can be initialized with an expression .
#include <iostream>
using namespace std;
int main()
{
double a = 12 * 3.25;
double b = a + 1.112;
cout << a << endl;
cout << b << endl;
a = a * 2 + b;
double c = a + b * a;
cout << c << endl;
return 0;
}
Block {} Internal scope can define variables with the same name outside the domain , The external variables are hidden in this fast .
#include <iostream>
using namespace std;
int main()
{
double a;
cin >> a;
{
int a = 1;
a = a * 10 + 4;
cout << a << endl;
}
cout << a << endl;
return 0;
}
for Loops can define local variables .
#include <iostream>
using namespace std;
int main()
{
int i = 0;
for (int i = 0; i < 4; i++)
{
cout << i << endl; // Output loop local variable
}
cout << i << endl; // Output main Medium i
for (i = 0; i < 4; i++)
{
for (int i = 0; i < 4; i++) // Redefine local variables for each round i
{
cout << i << " ";
}
cout << endl;
}
return 0;
}
Access the global variable with the same name as the variable of the internal scope , To qualify with global scope ::.
#include <iostream>
using namespace std;
double a = 123;
int main()
{
double a = 256;
cout << a << endl; // local variable a
cout << ::a << endl; // Global variables a
return 0;
}
边栏推荐
- The latest second edition of comic novels, listening to books, three in one, complete source code / integrated visa free interface / building tutorials / with acquisition interface
- Kotlin companion object vs global function
- makefile详解
- 向日葵远程控制为何采用BGP服务器?自动最优路线、跨运营商高速传输
- 无法一次粘贴多张图片
- Vs code must know and know 20 shortcut keys!
- 容斥原理
- How does DataGrid export and recover the entire database data, using a single SQL file
- NXP i.mx8mp-deepviewrt
- 数字孪生实际应用案例-智慧能源篇
猜你喜欢

(nowcoder22529C)dinner(容斥原理+排列组合)

Makefile details

Reproduce 20 character short domain name bypass and XSS related knowledge points

(2022杭电多校三)1011-Link is as bear(思维+线性基)

C language programming | exchange binary odd and even bits (macro Implementation)

【科技1】

暴力递归到动态规划 01 (机器人移动)

Rongyun IM & RTC capabilities on new sites

2022-07-28 study notes of group 4 self-cultivation class (every day)

(newcoder 15079)无关(容斥原理)
随机推荐
Overestimated test driven development?
Naive Bayes -- continuous data
Simple understanding of CDN, SDN and QoS
Military product development process - transition phase
Example analysis of while, repeat and loop loops in MySQL process control
Ten thousand words detailed Google play online application standard package format AAB
Instance setup flask service (simple version)
Numpy acceleration -- > cupy installation
Anti vulnerability · benefit from uncertainty --- management?
Swing V2: towards a larger model with larger capacity and higher resolution
Introduction to JVM foundation I (memory structure)
MOS tube - rapid recovery application notes (II) [parameters and applications]
Realize multi-level linkage through recursion
1. 头文件-注释-命名空间-标准输入输出流
Leetcode 1331 array sequence number conversion [map] the leetcode path of heroding
【科技1】
Sleuth+zipkin to track distributed service links
Precautions for using latex
for_ Example of each usage
Environment configuration stepping pit during colab use