Job Six summary

Source: Internet
Author: User
Tags types of functions

First, the Knowledge point

Definition of the function:

1. A function is a standalone program module that accomplishes a specific task, including library functions and custom functions. For example: scanf (), printf () is a library function, cylinder (), and fact () is a custom function.

2. General form of function definition:

function type function name (formal parameter table)/* First Part/*

{

function implementation Process */function Body */

}

3. Function call: Any C language execution, starting from the main function main (), if you encounter a function call, the main function will pause execution, instead of executing the corresponding function, the function will return the main function after execution, and then continue to execute from the original paused position.

4. function call Procedure:

The Main () function runs to:

Volume=cylinder (radius,height), call the cylinder () function, pause the main () function, and pass the values of the variable radius and height to the parameters R and H.

The computer goes to the Execute cylinder () function, and the parameters R and H accept the variable radius and height values.

The function cylinder () executes "return result", ends the function run, takes the result of the function, and returns to the main () function where he called.

The computer resumes from its previous location, assigns the return value to the variable volume, and outputs the volume.

Cases:

Double cylinder (double r,doubke h)

(double result; '

Result=3.14*r*r*h;

Return result;

}

5. Function classification: From the user's point of view C language functions are divided into two categories: library functions and user-defined functions, from the formal into two categories: no parameter function: No need to pass parameters to the function. Printstar () and parameter functions: you need to pass the necessary arguments to the function. Cylinder (R,H) Max (A, b); there are two types of functions that have no return value: A function that has a return value: The functions are evaluated, a definite result is obtained, and the result needs to be echoed back. Cylinder (r,h) Mac (A, B) no return value parameters: The function simply completes a series of steps and does not need to echo any result of the operation. Printstar () Printmessage ()

6. Type identifier: The type of the function, which is the same type as the return statement value. Can be understood as the type of the final result of a function, which can be any valid type, but saves time by default to reshape. If the function has no return value, the type identifier is (void)

7. Function Name: His name to conform to the C language identifier naming rules, consisting of letters, numbers and underscores, where the first character must be a letter or an underscore.

The function name must be unique and cannot be the same as the variable or formal parameter name in the function body.

8. Function parameter Passing Description:

An argument can be a constant, a variable, an expression. However, there must be a definite value. A parameter is a variable and you must specify a type. During parameter passing, the argument copies the value to the formal parameter. In C, the passing of a parameter is a "value pass", which is a single pass. Data can only be passed to formal parameters by arguments, not by parameters to arguments. The formal parameter and the argument one by one correspond, the quantity is consistent, the type is consistent, the order is consistent. Formal parameters do not occupy memory until the function is called, memory is allocated for the parameter when the function is called, the call ends, and memory is freed. Return function: Ends the function's run. Returns the main function with the result of the operation. If the return statement is: Return, it means that only the call point of the calling function is returned, without the return value. In a function, the return statement can appear multiple times, but each execution function has a return statement executed.

9. function declaration

A. Function type function name (parameter table)

Double cylinder (double r,double h); writes only the first line in the function definition (first part of the functions) and ends with a semicolon.

Function declaration: Describes the type and parameters of the function, to ensure that the program compiles to determine whether the call to the function is correct. In the case of a library function, the header file should be referenced at the beginning of the file. If the called function definition is behind the call to his function: The called function should be declared in the keynote function. The called function is declared before all functions, so it is not necessary to declare it in the keynote function. If the called function is defined in front of the calling function, it may not be declared before the keynote function.

Job Six summary

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.