<1> function declaration
I recently read the C language, which is very confusing. In some cases, function declaration is not available in some cases.
I checked the teaching material, made a summary, copied the pen, and recorded it online. I have forgotten it!
Function declaration is not required in the following three cases:
1. If the return type of the called function is integer or char, the system will take care of it.
Example:
// Code 1 # include <stdio. h> int main () {int A = 30; double D = 4.4334; printf ("A = % d", call (a); Return 0 ;} int call (INT d) {printf ("helloworld \ n"); Return D ;}
Correct. What if I change the return type of the call function to double?
// Code 2 # include <stdio. h> int main () {int A = 30; double D = 4.4334; printf ("d = % F", call (d); Return 0 ;} double call (double D) {printf ("helloworld \ n"); Return D ;}
GCC indicates that the type of the call function is confusing ~
D:\prj\core_c>gcc demo.c -o demo.outdemo.c:8:8: error: conflicting types for 'call'demo.c:5:16: note: previous implicit declaration of 'call' was here
2. The called function is defined before the main function.
The call method in Code 2 above is before Main, so there will be no problem.
3. Declare the called function before defining all functions.
// Code 4 # include <stdio. h> double call (double D); int main () {int A = 30; double D = 4.4334; printf ("d = % F", call (d )); return 0;} double call (double D) {printf ("helloworld \ n"); Return D ;}
It is equivalent to making an external statement.
<2> parameters.
Example:
(1) function declaration, saving the variable name.
Int getmax (int A, int B); // you can save the variable name to facilitate compilation of system errors: int getmax (INT, INT );
(2). You do not need to allocate memory for the shape parameters in macro definition.
#define P(d) printf("%d",d)
Beginner's notes.