function declaration and definition
variables :
Before you talk about variables, let's talk about the concepts of declaring and defining variables.
-
- Declaring a variable means describing the type of the variable to the compiler, but not allocating storage space for the variable.
- Defining a variable means allocating storage space for the variable while declaring it, and initializing the variable while defining the variable.
Local variables: typically only definitions are not declared.
Global variables: typically defined in a source file and declared in a header file.
A variable defined inside a function becomes a local variable, which is valid within this function.
The local variable in the function, if the type is not defined, it defaults to auto variable auto,
For example: int a,b=2; It is equivalent to auto int, A, b = 2;
Static local variable: static
A static local variable is a local variable defined and declared inside a function that is used only by this function.
A static local variable does not disappear after the function ends and retains its value, that is, the storage unit is not freed.
The variable already has a value, which is the value at the end of the last function.
A static local variable allocates a storage unit in a static storage area and is not released during the entire run of the program.
Static local variables are initialized at compile time and are only assigned once
Global variables:
Variables defined outside the local scope become global variables
It can be shared by other functions in this file, and global variables are stored statically and are allocated at compile time
Static outside variable static
Static external variables can only be used in the current file, and all static external variables are declared and defined in the source file.
External variables: extern
When you define a global variable in a function, its default format is the external variable type, and the external variable type should be defined in the source file.
Declared in the header file, it can be used in multiple files
Function:
Intrinsic functions:
The Declaration and definition of an intrinsic function is more in the current source file, while the outer function is declared in the header file, defined in the source file.
Advantages of using Intrinsic functions:
-
-
-
- The use of the function is limited to the current file only.
- Avoid conflicts with functions with the same name in a file.
External functions:
Functions that can be used outside of the current file are called external functions
C language, declaration and definition of functions