C language, declaration and definition of functions

Source: Internet
Author: User

function declaration and definition

  variables :

Before you talk about variables, let's talk about the concepts of declaring and defining variables.

      1. Declaring a variable means describing the type of the variable to the compiler, but not allocating storage space for the variable.
      2. Defining a variable means allocating storage space for the variable while declaring it, and initializing the variable while defining the variable.

Local variables: typically only definitions are not declared.

Global variables: typically defined in a source file and declared in a header file.

  

A variable defined inside a function becomes a local variable, which is valid within this function.

The local variable in the function, if the type is not defined, it defaults to auto variable auto,

For example: int a,b=2; It is equivalent to auto int, A, b = 2;

  Static local variable: static

A static local variable is a local variable defined and declared inside a function that is used only by this function.

A static local variable does not disappear after the function ends and retains its value, that is, the storage unit is not freed.

The variable already has a value, which is the value at the end of the last function.

A static local variable allocates a storage unit in a static storage area and is not released during the entire run of the program.

Static local variables are initialized at compile time and are only assigned once

  Global variables:

Variables defined outside the local scope become global variables

It can be shared by other functions in this file, and global variables are stored statically and are allocated at compile time

  Static outside variable static

Static external variables can only be used in the current file, and all static external variables are declared and defined in the source file.

  External variables: extern

When you define a global variable in a function, its default format is the external variable type, and the external variable type should be defined in the source file.

Declared in the header file, it can be used in multiple files

  Function:

Intrinsic functions:

The Declaration and definition of an intrinsic function is more in the current source file, while the outer function is declared in the header file, defined in the source file.

Advantages of using Intrinsic functions:

          1. The use of the function is limited to the current file only.
          2. Avoid conflicts with functions with the same name in a file.

External functions:

Functions that can be used outside of the current file are called external functions

        

      

  

C language, declaration and definition of functions

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.