Functions and variables (global variables) are declared and defined ,
For functions:
In the same file, if the function fun_1 call fun_2, if fun_2 is defined after fun_1, declare fun_1 before Fun_2, as follows:
void Fun_2 ()//Declaration
Void fun_1 () {
...
Fun_2 ();
...
} Call fun_2
void Fun_2 () {...}//Definition
In different files, when calling an external function, you need to first #include the corresponding header file (the header file contains the declaration of the function, you can import the source file directly, but not recommended), and then call the function.
For variables:
Whether in the same file or in a different file, use must be declared in advance before the definition, and use the keyword extern when declaring:
Conditions within the same file:
extern int B;
Main ()
{
printf ("b =%d\n", b);
}
int b = 3;
In addition, its declarations are used to describe the properties of a variable (mainly the type of the variable) and can be declared multiple times, and the definition of a variable will cause the allocation of the storage and can only be defined once.
Note: definition is a special kind of declaration.
int sp;
Double Val[maxval];
These two statements define the variable SP and Val and allocate storage units for them, and the two statements can also be declared as the remainder of the source file.
extern int sp;
extern double val[];
These two statements are only declared and do not allocate storage space
Note: The length of the array must be specified in the definition, but the extern declaration does not necessarily specify the length of the array.
Variable Initialization : assign values at the same time as the definition of a variable, and then assign a value that is not initialized.