文章目录
- Summary of Error-prone points
-
- [definition] definition of Scope
- [definition] A lookup mechanism for nested scopes
- [Error 1] Variable scope masking (also known as variable masking or hiding)
- [Error 2] The function is passed as a value, and the pointer is passed as a value
- [Error 3] null pointer dereference - Illegal memory access
- [attention] C language the rules of variables automatically initialize
- [Error 4] attetion: local variables need to initialize
- [Error 5] the `switch` sentence falls through in the absence of `break`
- [Error 6]
- [Error 7]
- [Error 8]
- [Error 9]
- [Error ]
- [Error ]
Summary of Error-prone points
[definition] definition of Scope
作用域的概念
在编程中,作用域(Scope)是一个非常重要的概念,它决定了程序中某个标识符(如变量、函数名等)的可见性和生命周期。简单来说,作用域就是程序中一个标识符可以被有效访问的代码区域。
[definition] A lookup mechanism for nested scopes
嵌套作用域的查找机制
在嵌套的作用域结构中,内部作用域可以访问其外部作用域中的标识符,但外部作用域无法直接访问内部作用域中的标识符。这种嵌套关系形成了从内到外的查找路径。
当在程序中尝试访问一个标识符时,编译器或解释器会按照以下规则进行查找:
- 当前作用域查找: