C Language Learning Tutorial fifth chapter-Functions (1)

Source: Internet
Author: User
Tags definition control characters function definition function prototype lowercase mathematical functions

Overview

In the first chapter has been introduced, C source program is composed of functions. Although there is only one main function main () in the programs in the previous chapters, the utility is often composed of multiple functions. function is the basic module of C source program, which realizes specific function by calling function module. Functions in C language are equivalent to subroutines in other advanced languages. C Language not only provides a very rich library functions (such as Turbo C,ms C provides more than 300 library functions), but also allows users to establish their own defined functions. Users can weave their own algorithm into a relatively independent function module, and then use the method to invoke the function.

It can be said that all the work of the C program is done by a variety of functions, so also called C language functional language. Because of the function-modular structure, C language is easy to realize the structural programming. The structure of the program is clear, easy to write, read and debug the program.

Functions can be categorized from different angles in C language.

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

(1) Library function
Provided by the C system, the user does not need to define, and does not have to be a type description in the program, simply include the function prototype before the program can be called directly in the program. The functions of printf, scanf, GetChar, Putchar, gets, puts and strcat are used repeatedly in the examples in the previous chapters.

(2) User-defined functions
A function written by the user as needed. For user-defined functions, the function itself is defined not only in the program, but also by the type description of the called function in the keynote function module before it can be used.

2. C language functions and other languages in the functions and processes of two functions, from this point of view, but also can be divided into functions with return value function and no return value function two kinds.

(1) There is a return value function
When such a function is called, an execution result, called a function return value, is returned to the caller. such as mathematical functions belong to this type of function. The user-defined function that returns the value of a function must explicitly return the type of the value in the function definition and function description.

(2) No return value function
This class of functions is used to complete a specific processing task and does not return function values to the caller after the execution completes. This type of function is similar to the process of other languages. Because a function does not need to return a value, the user can specify that it returns "null type" when defining such a function, and the descriptor for the null type is "void".

3. From the point of view of the data transmission between the keynote function and the modulated function, it can be divided into two kinds: the parameterless function and the parameter function.

(1) Non-parametric function
function definitions, function descriptions, and function calls take no parameters. There is no parameter transfer between the keynote function and the modulated function. This type of function is typically used to complete a set of specified functions that can return or not return function values.

(2) A parameter function
Also known as the band-parameter function. There are parameters in the function definition and function description, called formal parameters (referred to as formal arguments). A parameter must also be given when the function is called, called the actual argument (referred to as the argument). When a function call is made, the calling function will pass the value of the argument to the formal parameter for use by the modulated function.

4. The C language provides an extremely rich library function that can be categorized from a functional perspective.
(1) Character type classification function
Used to classify characters by ASCII code: Letters, numbers, control characters, separators, uppercase and lowercase, and so on.
(2) Conversion function
For converting characters or strings, converting between characters and various numeric quantities (integer, solid, etc.), and converting between large and lowercase.
(3) Directory path function
Used for file directories and path operations.
(4) Diagnostic function
For internal error detection.
(5) Graphics function
For screen management and various graphics features.
(6) Input and output function
Used to complete the input/output function.
(7) Interface function
For interfaces with Dos,bios and hardware.
(8) String function
For string manipulation and processing.
(9) Memory management function
For memory management.
(10) Mathematical functions
Used for mathematical function calculations.
(11) Date and time functions
Used for date, time conversion operations.
(12) Process Control function
For process management and control.
(13) Other functions
for various other functions.

The above kinds of functions not only quantity, and some also need hardware knowledge will use, so want to master it requires a longer learning process. Should first master some of the most basic, most commonly used functions, and then gradually in-depth. Due to space, this book only introduces a very small number of library functions, the rest of the reader can refer to the manual as needed.

It should also be noted that in the C language, all function definitions, including the main function main, are parallel. That is, in the function body of a function, you cannot define another function, that is, you cannot nest the definition. However, calls are allowed between functions, and nested calls are allowed. The caller is customarily called the calling function. Functions can also call themselves, called recursive calls. The main function is the main function, which can call other functions and not be called by other functions. Therefore, the execution of the C program always starts with the main function, completes the call to the other function, returns to the main function, and finally ends the entire program by the main function. A C source program must have, and can only have one main function main.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.