当前位置:网站首页>2.3 learning content

2.3 learning content

2022-07-05 15:25:00 Houli crab 670

  1. Local and global variables
  2. The scope and life cycle of variables
  3. stay VS2021 Use traditional scanf The reason for the warning

The priority of local variables and global variables and how to distinguish

When the variables of local variables and global variables are the same , Meeting “ Local priority global ”
Generally speaking , Inside the braces are local variables , Outside the braces are global variables ( I used to think that global variables are also in the main function , Today, I learned that it is a local variable )

The scope and life cycle of variables

Scope , Generally speaking, it is the range of variables . The life cycle is the period of time from the definition of a variable to leaving its function .
About the scope of variables , If you define a variable in a source file (int a) Then I also want to use this variable in another source file , Direct write extern int a. Then you can use it .

scanf The reason for the warning

because scanf It doesn't care about the string you enter ( Or numbers ) Whether it exceeds the originally defined space . For example, I define a character array (char a[5]) But I input more than five characters (ashdjdjj), The result of running is not ashdj It is ashdjdjj, And the program will crash . Simply put “ The function has insufficient restrictions on the type and number of parameters .”( I found it online haha , Chinese is not good , Language is not refined )

原网站

版权声明
本文为[Houli crab 670]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140514119822.html