当前位置:网站首页>2022_ 2_ 16 the second day of learning C language_ Constant, variable
2022_ 2_ 16 the second day of learning C language_ Constant, variable
2022-06-29 00:27:00 【Keou keou】
c Language standards
sizeof(long) >= sizeof(int)
Constant 、 Variable
Some values in life are constant ( such as : PI , Gender , Id card number , Blood type, etc ) Constant
Some values are variable ( such as : Age , weight , Salary, etc ) Variable
Constant value ,C The concept of constant is used to express , Variable value C In languages, variables are used to represent
How to define variables :
int age=150;
float weight=45.5f;
char ch=“w”;
Classification of variables
local variable
Global variables
int main()
{
// It means age
//20
short age = 20;// Request two bytes from memory =16 individual bit position , For storage 20
float weighe = 95.6f;// Apply to memory 4 Bytes =32bit position , Store decimals
return 0;
}
int num1 = 20;// Global variables - Defined in the code block ({}) Other variables
int main()
{
int num2 = 10;// local variable - Defined in the code block ({}) Internal variables
return 0;
}
int a = 100;
int main()
{
int a = 10;
// It is recommended that the names of local variables and global variables should not be the same - Easy to misunderstand -bug
// When local and global variables have the same name , Local variables take precedence
printf("%d\n", a);
return 0;
}
Use of variables
// Use of variables
int main()
{
// Calculate the sum of two numbers
int num1 = 0;
int num2 = 2;
int sum = 0;
// input data - Using input functions scanf
scanf("%d%d", &num1, &num2);// Take the address symbol &
//C Phonetic grammar regulations , The variable should be defined at the front of the current code block
sum=num1 + num2;
printf("sum=%d\n", sum);
return 0;
}
The scope and life cycle of variables
Scope :
Scope (scope) Programming concept , Generally speaking , The names used to summarize a piece of program code are not always valid / Usable
The scope of the code that defines the usability of the name is the scope of the name .
1、 The action of a local variable on the local range of the variable .
2、 The scope of the global variable is the scope of the whole project .
// The scope of a local variable
int main()
{
int num = 0;
{printf("num=%d\n",num); }
return 0;
}
// Scope of global variables
int global = 2020;
void test()
{
printf("test()--%d\n", global);
}
int main()
{
test();
printf("%d\n", global);
return 0;
}
int main()
{
// undeclared identifier
// Make a statement extern External symbol
extern int g_val;
printf("g_val = %d\n", g_val);
return 0;
}
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
// Life cycle :
int main()// Local life cycle
{
{
int a = 10;
printf("a=%d\n", a);//OK
}
printf("a=%d\n", a);//error
return 0;
}
// The life cycle of global variables =main The life cycle of a function = The whole life cycle of the program
Finally, I finished the first video of brother Peng ~ It doesn't feel particularly difficult to understand in the early stage , Each line is typed by itself , Keep going !
Recent summary :
C Speech is developed from binary language to assembly language to mnemonic B Language , Then derived C Language . Make the language easier to use , Produced C The standard of language (ANSI C)
main function -printf Need a lead file #include<stdio.h>- data type (7 Kind of )- Variable ( Types are used to create variables )- local variable / Global variables - The life cycle and scope of variables
Looking forward to the next issue ......
边栏推荐
- Reprint: VTK notes - clipping and segmentation - irregular closed loop clipping -vtkselectpolydata class (black mountain old demon)
- 请问同花顺上开户安全吗
- ES6:let、const、箭头函数
- JDBC连接、断开数据库的封装
- Cross domain problem of canvas drawing caused by background image cache
- 12. Détection d'objets Mask rcnn
- 三个pwn题
- EditText监听焦点
- 旋转接头安装使用注意事项
- This thing is called a jump watch?
猜你喜欢

6.28 学习内容

Comparison between winding process and lamination process

Haskell configuring vs code development environment (june2022)
![[buuctf.reverse] 131-135](/img/c2/b8b06c8191af2c75bf4ad5c82feaea.png)
[buuctf.reverse] 131-135

运营级智慧校园系统源码 智慧校园小程序源码+电子班牌+人脸识别系统

随笔记:插入排序 --from wcc

Software testing tools: complete and precise

矩 阵 压 缩

Use and principle of handlerthread

Typescript -- Section 5: classes
随机推荐
MySQL 8.0 above reporting 2058 solution
Typescript -- Section 5: classes
How the slip ring motor works
三個pwn題
[image registration] improved SAR image registration based on sar-sift with matlab code
Use and principle of handlerthread
Comics | goodbye, postman! One stop collaboration makes apipost more fragrant!
MapReduce案例
MySQL high availability dual master synchronization
Daily question 1: remove elements
Comparison between winding process and lamination process
What will be done after digital IC Verification?
Software testing tools: complete and precise
Reasons for high price of optical fiber slip ring
The company has a new Post-00 test paper king. The old oilman said that he could not do it. He has been
Reprint: VTK notes - clipping and segmentation - 3D curve or geometric cutting volume data (black mountain old demon)
Chrome浏览器的基本使用
每日一练:删除有序数组中的重复项
be based on. NETCORE development blog project starblog - (13) add friendship link function
如果你会玩这4个自媒体运营工具,副业收入6000+很轻松