当前位置:网站首页>Share a multiple-choice question about variables (including global variables, local variables, the scope of variables, and life cycle knowledge points)
Share a multiple-choice question about variables (including global variables, local variables, the scope of variables, and life cycle knowledge points)
2022-07-27 05:36:00 【vpurple__】
Catalog
4.1 Local variable and global variable
4.2 Scope of variable 、 Life cycle
Recommended reading order :
1. subject ->3. answer ->2. Topic analysis ->4. Topic knowledge
1. subject
1、 Perform the following procedure , The correct output is ( )
#include<stdio.h>
int x=5,y=7;
void swap()
{
int z;
z=x;
x=y;
y=z;
}
int main()
{
int x=3,y=8;
swap();
printf("%d,%d\n",x, y);
return 0;
}A: 5,7 B: 7,5 C: 3,8 D: 8,3
2. Topic analysis
This is a typical study of global variables 、 Local variables and the scope and life cycle of variables .
It's better to watch by number

3. Question answer
C:3,8
4. Topic knowledge
4.1 Local variable and global variable

In the same range , Local variable names cannot be the same , Cannot be defined repeatedly .

When a local variable has the same name as a global variable , Local variables take precedence .
It is recommended not to name global variables and local variables the same .

4.2 Scope of variable 、 Life cycle
Scope
Scope (scope) It's a programming concept , Generally speaking , The names used in a program are not always valid / Usable , The scope of the code that defines the usability of the name is the scope of the name . In a popular sense , Where does this variable work , Where is its scope .
1. The scope of a local variable is the local scope of the variable .
The demonstration is as follows :

2. The scope of global variables is the whole project .

Life cycle
The life cycle of a variable is the period between the creation of a variable and its destruction .
1. The life cycle of a local variable is : Enter the scope lifecycle begins , Out of scope life cycle ends .
2. The life cycle of global variables is : The whole life cycle of the program .
边栏推荐
猜你喜欢

Idea remote debugging

块,行内块元素之间存在间隙

Li Hongyi machine learning team learning punch in activity day05 --- skills of network design

Li Hongyi machine learning team learning punch in activity day04 - Introduction to deep learning and back propagation mechanism

redis发布订阅模式

C WPF uses listbox to implement ruler control

SQL database → constraint → design → multi table query → transaction

Li Hongyi machine learning team learning punch in activity day03 --- error and gradient decline

李宏毅机器学习组队学习打卡活动day03---误差和梯度下降

redis集群
随机推荐
Three waiting methods of selenium and three processing methods of alert pop-up
Utility gadget: kotlin code snippet
How to quickly and effectively solve the problem of database connection failure
Day5 --- Flask-RESTful请求响应与SQLAlchemy基础
程序环境和预处理(上):一个程序是怎么成功运行的?
flask蓝图
背景图片相关应用-铺满,自适应
Xiaomi mall project_ register
下载url-loader,用limit指定图片大小后,显示不出图片
Collation of several difficult methods in pytorch --gather & squeeze & unsqueeze
Rolling Division
Multiplication sorting in torch, * & torch. Mul () & torch. MV () & torch. Mm () & torch. Dot () & @ & torch. Mutmal ()
flask一对多数据库创建,基础增删改查
Source code of document type full-text retrieval knowledge base management system
Flask的使用
Flask对模型类的操作
后台实现spu管理
Hi3516DV300环境搭建
Program environment and preprocessing (Part 1): how does a program run successfully?
2021 Niuke multi school training camp 5 (question b)