Confused about declaration, definition

This question already has an answer here:

  • Variable declaration vs definition 3 answers
  • What is the difference between a definition and a declaration? 25 answers

  • int a; is both a declaration (the variable can be used) and a definition (it has its own memory) but if it is an automatic variable, it is not initialized.

    extern int a; is a mere declaration and is not a definition.


    From here:

    Most of the time, when you declare a variable, you are also providing the definition. What does it mean to define a variable, exactly? It means you are telling the compiler where to create the storage for that variable. For example, if you write:

    int x;
    int main()
    {
        x = 3;
    }
    

    The line int x; both declares and defines the variable; it effectively says, "create a variable named x, of type int. Also, the storage for the variable is that it is a global variable defined in the object file associated with this source file

    this is a part from site more relevant to your question please refer to the link for further your misconception will be hopefully cleared http://www.cprogramming.com/declare_vs_define.html

    链接地址: http://www.djcxy.com/p/40636.html

    上一篇: 使用在C ++中动态分配的数组有什么问题?

    下一篇: 对宣言,定义感到困惑