The difference between the declaration and definition of "non-original" C language

Source: Internet
Author: User

Original address: http://www.cnblogs.com/haore147/p/3647466.html

What is a definition? What is a statement? What is the difference between them?

As an example:

12 A)inti;B)extern inti;(关于extern,后面解释)


Which is the definition? Which is the declaration? Or are they all definitions or declarations? Almost none of the students I have ever taught can answer this question. This very important concept has never been mentioned in college!

What is definition: the so-called definition is (the compiler) creates an object, allocates a piece of memory for the object, and gives it a name, which is what we often call the variable name or object name. But notice that once this name is matched to this memory (it is conceivable that this name is married to this space, there is no dowry.) ^_^), they are die, the life will not abandon. And the location of this memory cannot be changed. A variable or object within a certain area (such as a function, global, etc.) can only be defined once, if defined more than once, the compiler will prompt you to repeat the definition
The same variable or object.


What is a statement: There are twofold meanings, as follows:


The first meaning: tell the compiler, this name has been matched to a piece of memory (she has been married, where will I go?) Why melancholy, only gruel), the following code uses a variable or object is defined elsewhere. A declaration can occur more than once.

The second meaning: tell the compiler, my name I first booked, and other places can no longer use it as a variable name or object name. For example, you put a book in one of the seats in the Library study room, indicating that the seat has been booked and that no one else will be allowed to use it. In fact, you are not seated in this seat at this time. The most typical example of such a declaration is the declaration of a function parameter, for example:

1 voidfun(int i, charc);


Well, such an explanation, we can make it very clear: a) is a definition; B) is a statement.


The difference between them is clear, too. Remember that defining the declaration is the most important difference: the definition creates an object and declares the variable for that extern to be declared in another file (or as a reference variable).

The object allocates memory, declares no memory allocated (a gruel, a drunk. ^_^).

Reference: Chengzhong Teacher's "C Language Depth analysis".

The difference between the declaration and definition of "non-original" C language

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.