Declaration vs definition in C

前端 未结 4 963
余生分开走
余生分开走 2020-12-20 00:06

Consider the code:

int main(void)
{
    int a;
}

As far as I know, int a; is a definition, as it causes storage to be reserved

4条回答
  •  我在风中等你
    2020-12-20 00:32

    int a;
    

    This is a definition There is a memory allocated for variable a

    extern int a;
    

    This is a declaration. Memory is not allocated because it is not defined.

    Once a variable is defined you can use the address of it which is totally legal.

提交回复
热议问题