Discuss the definition and declaration in C

Source: Internet
Author: User

For students .:

1. int I;
2. int I = 0;
3. extern int I;

First, you can think of it as a definition or declaration. This is determined by different compilers, but most of them are declarations. They are defined only when I is assigned a value. it is declared. the compiler will tell me that this symbol has been reserved and the second symbol is not allowed in this scope.
The second type is defined. I will tell the compiler that I have already bound to this memory. Other variables cannot occupy this memory unless, A variable or object can only be defined once in a certain region. Therefore, if you define a variable repeatedly, an error is returned, indicating that the variable is already defined!

{
Int I = 0;
Int I = 1;
}

W1.c: In function 'main ':
W1.c: 6: 13: error: redefinition of 'I'
W1.c: 5: 13: note: previous definition of 'I 'was here
Third, any compiler will regard it as a declaration!
It can be simplified to: The definition creates a name, and remains unique in this scope, and opens up memory for this name. declaring that no memory is allocated only tells you that this symbol is available. it may be used below, otherwise it will tell you that it has not been declared.

From Crazybaby's blog

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.