C language program design base lecture function

xiaoxiao2021-03-06  19

Overview

In the first chapter, the C source program is composed of a function. Although there is only one main function main () in the procedure of each chapter, the utility is often composed of multiple functions. The function is the basic module of the C source program, and the specific function is implemented by the call to the function module. The function in the C language is equivalent to the subroutine of other advanced languages. The C language not only provides an extremely rich library function (such as Turbo C, MS C provides more than 300 library functions), but also allows users to establish their own defined functions. Users can make their algorithms into a relatively independent function module, then use the function with the call.

It can be said that all of the works of the C program is done by a wide variety of functions, so the C language is also called a functional language. The C language is easy to implement structured programming due to the functional module structure. Make the hierarchy of the program clear, easy to write, read, and debug.

The function can be classified from different angles in the C language.

1. From the perspective of the function definition, the function can be divided into two types of library functions and user-defined functions.

(1) library function

Provided by the C system, the user does not have to define, nor does it need to be described in the program, just call the header file that contains the function prototype before the program can be called directly. In the first chapter, it is repeatedly used to use the printf, scanf, getcha, putcha, gets, puts, and strcat, etc.

(2) User definition function

The function written by the user as needed. For user-defined functions, it is necessary to define a function itself in the program, but also in the Motor Module, the modular function must be described, and then it can be used.

2. The function of the C language has both functions and processes in other languages. From this perspective, the function can be divided into two types of return value and non-return value function.

(1) Return value function

After this class function is called, it will return an execution result to the caller, referred to as a function return value. If the mathematical function is such a function. This function that is defined by the user must return a function value must be explicitly returned in the function definition and function description.

(2) No reference value

Such functions are used to complete an specific processing task, and do not return a function value to the caller after execution. Such functions are similar to the process of other languages. Since the function does not have to return a value, the user can specify its return to "empty type" when defining such a function, and the empty type is "Void".

3. From the perspective of data transfer from the main adjustment function and the modulated function, it can be divided into two kinds of no reference functions and between the number of functions.

(1) None of the function

Function definition, function description, and function calls are not parameters. Parameter transfer is not performed between the main adjustment function and the modulated function. Such functions are usually used to complete a set of specified features, which can return or do not return a function value.

(2) have a reference function

Also known as the band reference function. There is a parameter when the function definition and function description are called, called a formal parameter (referred to as a meticulous). Parameters must also be given when the function call is called, called the actual parameter (referred to as inform). When performing a function call, the main adjustment will transmit the value of the value of the argument to the invitiveing ​​function.

4. The C language provides an extremely rich library function, which can be classified by the functional angle.

(1) Character type classification function

Used to classify against characters: letters, numbers, control characters, separators, uppercase letters, etc.

(2) Conversion function

Conversion for characters or strings; conversion between characters and various digital quantities (integer, real, etc.); transitions between large and lowercases.

(3) Directory path functions

Used for file directory and path operation.

(4) Diagnostic function

For internal error detection.

(5) Graphics function

Used for screen management and various graphics functions.

(6) Input and output functions

Used to complete the input and output function.

(7) Interface function

Used for interfaces with DOS, BIOS, and hardware.

(8) String function

Used for string operation and processing.

(9) Memory management function

Used for memory management.

(10) Mathematical functions

Used for mathematical functions.

(11) Date and time functions

Used for dates, time conversion operations.

(12) Process control function is used for process management and control.

(13) Other functions

Used for other functions. The above various types of functions are not only a number, but some need hardware knowledge will be used, so they need a longer learning process. You should first grasp some of the most basic, most common functions, and then gradually deeply. Due to the space relationship, this book only introduces a few partial library functions, and the rest of the readers can check the relevant manual as needed.

It should also be noted that in the C language, all function definitions, including the main function main, is parallel. That is to say, in a function of a function, another function cannot be defined, ie the definition cannot be nested. However, the function is allowed to call each other and the nested call is allowed. It is used to call the caller as the main adjustment function. The function can also call yourself, called recursive calls. The main function is the main function, which can call other functions without allowing to be called by other functions. Therefore, the execution of the C program always begins with the main function, and then returns to the main function after the call to other functions, and finally the entire program is ended by the main function. A C source must have, and only one main function main.

转载请注明原文地址:https://www.9cbs.com/read-42705.html

New Post(0)