[C Language] use functions, and C language use functions

Source: Internet
Author: User

[C Language] use functions, and C language use functions

Bytes ------------------------------------------------------------------------------------------

// Function prototype Declaration: The function header ends with a semicolon to form a function prototype. Purpose: 1. Return type 2. function name 2. Parameter type (random name)
Void sum (int begin, int end );

// Function Definition void sum (int begin, int end) {int I; int sum = 0; for (I = begin; I <= end; I ++) {sum + = I;} printf ("% d to % d and % d are % d", begin, end, sum );}

Sum (10, 15); # void sum (int begin, int end): function header. # Void: return type. If void exists, only return with no value or return is used.
# Sum: function name;
# Int begin: parameter, including (type name ).
# In curly brackets: function body.
# Call a function: the function name (parameter value). It is not called without parentheses. If a parameter exists, the correct quantity and order are required. The parameter values are used to initialize parameters in the function in sequence.
# Return Value: return is written as a return or return expression. Do not use multiple return statements for a single exit. The final return value of 0 in the main function indicates that the operation is correct.


Call the function:
If the function has parameters, the number and type passed during the call must be correct. If they do not match, the compiler will perform some conversions, which may not be what you want; the function only transmits values rather than variables.


Local variable:
Local variables are defined in blocks, separate blocks (curly braces), function blocks, or statement blocks (such as if ).
Variables defined outside the block still exist in the block. variables defined in the block do not exist outside the block.
If the variables in the block are output outside the block, no output value exists.
If the block defines a variable with the same name as the outside, it overwrites the outside.
Variables with the same name cannot be defined in a block.
Local variables are not initialized by default.
The parameter is initialized when it enters the function.


Define three different parameter methods for a function:
Void d (int x );
Void d ();
Void d (int );

Link: http://www.cnblogs.com/farwish/p/4202576.html

@ Blackeye poet <www. chenwei. ws>

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.