C Language Learning Tutorial fifth chapter-Functions (10)

Source: Internet
Author: User
Tags definition function definition valid

internal functions and external functions

Once a function is defined, it can be called by another function. But when a source program consists of multiple source files, can a function defined in a source file be called by a function in another source file? For this reason, C also divides functions into two categories:

One, internal functions

If a function defined in a source file can only be called by a function in this file, and not by a function in the other file of the same source program, this function is called an internal letter.
Number. The general form of defining intrinsic functions is: Static type descriptor function name (formal parameter list) for example:
The static int f (int a,int b) Intrinsic function is also called a static function. However, the meaning of static statics here is not meant to be stored, but refers to the scope of the call to the function is limited to this file. Therefore, defining static functions with the same name in different source files does not cause confusion.

Second, external functions
External functions are valid throughout the source program and are defined in the general form of an extern type descriptor function name (formal parameter list), for example:
extern int f (int a,int B) is implied as extern if there is no indication of extern or static in the function definition. When calling external functions defined in other source files in a function of a source file, an extern description is applied to an external function. For example:
F1. C (source file one)
Main ()
{
extern int F1 (int i); /* External function description, indicating F1 letter
Number in other source files * *
......
}
F2. C (source file II)
extern int F1 (int i); /* External function definition * *
{
......
}

Summary of this chapter

1. Classification of functions
(1) Library function: The function provided by C system;
(2) User-defined function: A function defined by the user;
(3) A function with a return value returns the function value to the caller, indicating the function type (that is, the type of the return value);
(4) A function with no return value: The function value is not returned, and the null (void) type is indicated;
(5) A parametric function: The keynote function transmits data to the modulated function;
(6) Non-parametric function: There is no data transmission between the keynote function and the modulated function;
(7) Internal functions: Only functions used in the source file;
(8) External function: a function that can be used throughout the source program.

2. General form of function definition
The [extern/static] type descriptor function name ([formal parameter list]) is available in square brackets.

3. General form of function Description [extern] Type descriptor function name ([formal parameter list]);

4. function call general form function name ([argument list])

5. The parameters of the function are divided into formal parameters and actual parameters, the formal parameter appears in the function definition, the argument appears in the function call, the value of the argument is passed to the formal parameter when the function call occurs.

6. The value of the function refers to the return value of the function, which is returned by the return statement in the function.

7. The array name is sent as a function parameter without value transfer. The formal parameters and arguments are actually two names of the same array. As a result, the value of the parameter group changes, and the value of the real parameter group certainly changes.

8. C language, allow nested calls to functions and recursive calls to functions.

9. Variables can be categorized from three aspects, namely the data type of the variable, the scope of the variable and the storage type of the variable. In Chapter two, we introduce the data types of variables, and the scope of variables and the type of storage of variables are described in this chapter.

10. The scope of the variable refers to the valid range of the variable in the program, divided into local variables and global variables.

11. The storage type of variables refers to the way in which variables are stored in memory, which is divided into static and dynamic storage, indicating the lifetime of variables.

12. Variable classification attribute table storage mode storage type descriptor where to define the value of the lifetime scope assignment value can be assigned an initial type dynamic storage automatic variable auto register variable register Function or compound statement when invoked in a function or compound statement that defines it indefinite base type int or char external variable extern function entire source program static local variable statics function or compound statement static global variable statics The entire source program outside of a function defines its source file in 0 of any type within its function or compound statement.

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.