C language tutorial Chapter fifth: function

Has been introduced in the first chapter, the C source is a function of the composition. Although in each chapter program front has only one main function main (), but the practical procedures are often composed of multiple function. The function is the basic module of C source code, to achieve a specific function by function module calls. Subroutine in C language is equivalent to other high-level languages. C language not only provides a very rich library function (such as Turbo C, MS C provides more than 300 library function), function also allows users to set up their own definition. The user can take their own algorithms into a relatively independent function module, and calling a method to use the function.
It can be said that all the work of the C program is completed by a variety of functions, so it is also called the C language function language. Due to the adoption of the structure function modular and easy to realize structured program design in C language. So that the level of program structure clear, to facilitate the process of writing, reading, debugging.
In the C language of function classification from the different angle.
The 1 definition from the perspective of function, function can be divided into the function and user defined functions two.
(1) the library function
Provided by the C system, the user does not need to define, nor shall be type specified in the program, only need to call the program directly in the program before the packet containing the function prototype of the header file. Use printf, scanf, repeated getchar, putchar, gets, puts, strcat functions are such examples in each chapter in the front.
(2) the user defined function
By the user according to write function. For user-defined functions, not only in the procedure definition function itself, but also in the main function modules must also be transferred to the function of that type, and then to use.
Two kinds of function and the process of 2 C language function with other languages, from this point of view, can be divided into the function return value function and the function that has no return value two.
(1) a function return value
Such a function is called after the implementation will be a call to return to the execution result, known as the function return value. As a mathematical function is such that the function. By this user defined function to return the function value, must be in the description type explicitly return the value of the function definition and function.
(2) a function that has no return value
Such a specific function for the completion of treatment tasks, the executive not to call after the completion of the return value of a function. This function is similar to other languages. Because the function need not return a value, the user can specify it in return for "free type" in the definition of such a function, the type specifier empty for "void".
It can be divided into non parametric function and a function of the Senate two to see the 3 function from the tone and modulated data transmission function between angle.
(1) non parametric function
The function definition, function description and function calls are not with parameters. The calling function and be adjusted not parameter transfer function between. Such a function is usually used to accomplish a set of specific function returns the value of the function can be returned or not.
(2) a function of the Senate
Also known as functions with parameters. There are parameters in a function definition and function description, called the formal parameter (referred to as the Senate). Must also give the parameters in the function call, called actual parameters (referred to as arguments). A function call, the calling function will put the argument value is transmitted to the parameter be transferred for use function.
4 C language provides a very rich library function, these library functions can be classified as follows from the angle of function.
(1) the character type classification function
For classification of characters in ASCII Code: letters, numbers, control characters, separator, uppercase and lowercase letters, etc..
(2) transfer function
Used for converting a character or string; the characters and all kinds of digital (integer, real type etc.) between the conversion; conversion in the large, lower case between.
(3) the directory path function
For the file directory and the path of operation.
(4) the diagnosis function
For internal error detection.
(5) the graph function
For screen management and various graphics functions.
(6) input and output function
For the completion of the input and output function.
(7) interface function
Used with DOS, BIOS and the hardware interface.
(8) the string functions
For string manipulation and processing.
(9) memory management functions
For memory management.
(10) mathematical function
Mathematical function calculated for.
(11) the date and time functions
To date, time conversion operation.
(12) process control function
For process management and control.
(13) other functions

For other functions.

Above all kinds of functions not only the quantity, but also need some hardware knowledge will be used, so to master all of the learning process is in need of a longer. We should first master the most basic, the most commonly used functions, and then gradually in-depth. Due to the length of the relationship, this book features only a small part of the library functions, the rest of the readers may according to need to consult the relevant manuals.
It should be noted that, in the C language, all function definitions, including the main function main, are parallel. That is to say, a function in the function body, can no longer define another function, that is not nested definition. But the function between allowed to call each other, also allows nested call. On the habits of the caller is called tone function. Functions can also call their own, called recursive calls. The main function is the main function, it can call other functions, and does not allow the other function call. Therefore, the C program execution always begins from the main function, the completion of the other function call and then return to the main function, and finally by the end of the whole procedure of main function. A C source program must have, also can have only one main function main.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值