------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------
Static and extern
external functions : Defined functions can be accessed by this file and other files
intrinsic functions : Defined functions can only be accessed by this file and other files cannot be accessed
By default, all functions are external functions.
A complete definition of an external function:
Extem viod Test ()//extern can be omitted, default is omitted
{
printf ("Call the test function \ n")
}
Complete declaration of an external function:
Extem viod test (); You can omit extern, which is an external function by default
Define an intrinsic function:
Static Viod Test2 ()
{
printf ("Call test2")
}
Intrinsic functions cannot be accessed directly by other files, but can only be accessed indirectly
External functions with the same name are not allowed, and the names of intrinsic functions do not conflict within each file.
Static effects on functions:
1. Define an intrinsic function
2. Declaring intrinsic functions
The effect of extern on functions:
1. Complete definition of an external function
2. Complete declaration of an external function
static and extern effects on variables: defining and declaring an internal and external variable
External variables: Defined variables can be accessed by this file and other files
Internal variables: Defined variables can only be accessed by the file and cannot be accessed by other files
By default, all global variables are external variables
External variables of the same name in different files represent the same variable and can be defined repeatedly
Function
Any C language program is composed of one or more program segments, each of which has its own function, we generally call these program segments as functions, so you can say that the C language program is composed of functions.
Definition of a function
1. Purpose of defining functions
Encapsulates a common feature to facilitate later invocation
2. Steps to define a function
Function name: What are the names of functions?
Function Body: What is the function and what code it contains
3. Format
Fixed format (This is the case for many language functions)
return value type function name (formal parameter list)
{
function body
}
Example
Defines a function that calculates the number of two integers and
sum (int a, int b)
{
int c =a+b;
}
Formal parameters and arguments
Parameters: variables to be defined when a function is defined, parameters can have countless variables that cannot be defined in a function body and parameters
Arguments: The actual parameters of the function are passed in when the function is called, and the argument must correspond to the parameter one by one
Attention
If the base data type is a function parameter, it is purely a value pass, modifying the value of a function's internal parameter without affecting the value of the outer argument
A function can have no formal parameter, or it can have an infinite number of arguments
Define an internal variable:
static int b; and define the form of an intrinsic function almost
Internal variables of the same name in different files, not affecting each other
Dark Horse Programmer ——— Learn some notes of C language