Traditional Culture Encyclopedia - Traditional festivals - C language function definition and function declaration difference

C language function definition and function declaration difference

The poster can think of it this way, in C language, whether it is constants, variables, or functions, they can only be used if they are defined first.

When defining a function, your brain should be directed in the direction of general constants and variable definitions, and do not think about other things about the function first.

After defining it, put the definition of the function aside and ignore it.

Next is the function declaration. As we all know, C language consists of a main function main() and 0 or n ordinary functions.

Since the longer the code, the more functions are used. In order to reduce the confusion of functions, there must be a function name, just like the teacher calling the name. Declaring a function is like calling the name of a student.

In short, function definition is required by the system. If it is not defined, it will be an error. In fact, it is okay not to define the function declaration, but for convenience and reducing errors, it is artificially required to be declared.