Functions in C and supplemental descriptions of # include

Source: Internet
Author: User

C functions in the language:

The definition of a function is a encapsulated code snippet, each function can implement different functions

define the purpose of the function: encapsulate a common feature to make it easier to call later

What happens when you define a function: Add a new feature that is commonly used

Define the format of the function:

return value type function name (formal parameter list)

{

function body;

}

Formal parameters and arguments:

Formal parameter: A parameter that is followed by a function name when defining a function, for short, a formal parameter

Actual parameters: Invoking the specific data passed into the function, referred to as an actual argument

The number of arguments must be equal to the number of formal parameters

The function body cannot define the same variables as the parameters

If the base data type is a function parameter and is purely a value pass, modifying the value of the function's internal parameter does not affect the value of the outer argument.

A function can have no formal parameter, or it can have an infinite number of arguments

return value:

C The return value in the language is very weak.

return the role of:

1. Exit Function

2. returns a specific value to the function call

3. return to re-enter

4. If a function does not have a write return value type the default is int type

5.Void represents no return value

6. Even if the return value is clear, you can return no value

Function usage time should be noted:

    • The name of the function is not allowed by default

    • The definition of a function cannot be nested

    • Functions cannot be defined repeatedly, but can be declared repeatedly

    • function as long as the declaration must be defined: the compilation will only detect the syntax is not reasonable, do not detect the function has no definition; link error, it will detect whether the function is defined

Add:

#include the role

1. Copying Files

2. If the custom file is double quotation marks, if the system comes with the <>

3.#include file is intended to copy the declaration of the printf function

Link: Combine all relevant. o Target files in the project with the C language library to build the executable file

In the C language, the header file is the declaration of the function. The definition of the H function. c file.

If you want to use a function defined in a. c file, just include the declaration file for the. c file. h

int main ()

{

printf (" This function also has a return value, its return value type is int, it returns the value is the number of characters, and a Chinese character occupies 3 bytes");

return 0;// returns to the system if the return 0 program is normal exit;

}


This article is from the "I am the way of it Growth" blog, please be sure to keep this source http://jeason.blog.51cto.com/9704473/1596423

Functions in C and supplemental descriptions of # include

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.