Declaration, definition of the nature of the difference: there is no memory allocation

Source: Internet
Author: User

1. Statement:

In general, the name behind is added with the extern keyword, such as:

extern int // just a statement .

This process, which is a declaration, tells the compiler that the variable has been defined somewhere else, and that this only makes a basic declaration, and that the process does not allocate memory for it.

2. Definition:
int // declaration + Definition

The definition is complete, in fact, the definition contains the declaration, and the compiler allocates memory for it.

3. Initialize:
int ten;

Initialized, the defined memory is allocated later, let alone initialized.

4, one-step completion:
extern int 3.14;

It is generally done with declarations, definitions, initializations, and, of course, allocating memory.

5, the essence of the difference

The difference between declaring, defining, initializing, and essentially having no allocated memory. Obviously, the declaration simply tells the compiler that there is such a variable or function declaration, only to tell the compiler that there is such a function, the function or variable is defined in other places, so in the process did not allocate memory for it, definition, the compiler will allocate memory space for its variables. Initialized, it is completed, and the allocated memory is filled with the specified assignment.

6. Understanding

The declaration is understood as: a generic declaration that tells the compiler that this variable is an object created elsewhere.

The definition is understood as: a special declaration that allocates memory for a declared variable.

Declaration, definition of the nature of the difference: there is no memory allocation

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: 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.