The scope and storage of C language variables are described in detail

  • 2020-05-12 02:54:24
  • OfStack

Scope and storage of variables

1. Briefly describe the classification of variables by scope

Variables are divided by scope: into global variables and local variables Global variables: variables defined outside of all functions are called global variables Use of global variables: from the beginning of the definition to the end of the entire program Local variables: variables defined within a function or formal parameters of the function are collectively referred to as local variables Scope of use of local variables: variables defined within a function can only be used within this function

2. Describe the classification of variables according to the way they are stored

A static variable Automatic variables

Register variables [registers are hardware things that can store data inside cpu]

3. Briefly describe the problem of naming conflicts between global variables and local variables

1 > You cannot define two one-like local variables inside a function

2 > If the local variable is defined within a function with the same name as the global variable, the local variable will mask the global variable

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: