[Sophomore Upper][Review] Functions in C language

What is a function?

Functions are designed to solve a large number of problems of the same type. Functions are a tool

The basic unit of the C language is the function

Functions can be treated as a black box

Why do you need functions?

                1. Avoid repetitive operations

                2. Conducive to the modularization of the program


It is very simple to use a thing, but why this thing was born is also worth exploring

The black box can be used, but I don’t know how to deal with it internally


 What is a function?

4 minutes 30

logically:

        An independent block of code that performs a specific function

Physically:

        Can receive data [of course, you can not receive data]

        able to process the received data

        Can return the result of data processing [of course, you can also not return any value]

 


How to define a function?

1. The essence of a function definition is to describe in detail how a function can achieve a specific function

  2. The type of the return value of a function is also called the type of the function. If the type of the return value before the function name is different from the type in the return expression in the function execution body, the type of the return value of the final function will be the return value before the function name. Type prevails

        for example:

int test()
{
    return 8.8; // 因为函数的返回值类型是int 所以最终返回的值是8
}    

return terminates the function

        If the expression is empty, that is, return is empty, only the function is terminated, and no value is returned to the called function


Classification of functions

                Functions with and without parameters

                Functions that return a value and functions that do not return a value

                library functions and user-defined functions

                Ordinary functions and main functions

                                A program must have one and only one main function

                                The main function can call ordinary functions Ordinary functions cannot call the main function

                                Ordinary functions can call each other

                                The main function is the entry of the program and the exit of the program


Guess you like

Origin blog.csdn.net/IDApprentice/article/details/126705839